ci(provider): automatic updated versions

This commit is contained in:
Leifer Mendez
2023-01-01 15:07:11 +01:00
parent 928365dcaf
commit 3248dce03d
28 changed files with 237 additions and 28 deletions

50
.github/workflows/check-providers.yml vendored Normal file
View File

@@ -0,0 +1,50 @@
name: Build and Test
on:
push:
branches:
- dev
pull_request:
branches:
- dev
jobs:
check-npm:
name: Install Dependencies
runs-on: ubuntu-latest
needs:
- test-unit
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- run: corepack enable
- name: Install NPM Dependencies
run: yarn install --immutable --network-timeout 300000
- name: Check Baileys
run: yarn node ./scripts/checker.js baileys
- name: Check Venom
run: yarn node ./scripts/checker.js venom
- name: Check web-whatsapp
run: yarn node ./scripts/checker.js web-whatsapp
- name: Check Meta
run: yarn node ./scripts/checker.js meta
- name: Check Twilio
run: yarn node ./scripts/checker.js twilio
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "ci(providers): updated versions providers"

View File

@@ -1,4 +1,4 @@
name: 🤪 Build and Test
name: Build and Test
on:
push:

View File

@@ -1,4 +1,4 @@
name: 🙌 Revisando Colaboradores
name: Revisando Colaboradores
on:
pull_request:
branches:

View File

@@ -34,7 +34,7 @@ const startInteractive = async () => {
choices: [
{ title: 'whatsapp-web.js (gratis)', value: 'wweb' },
{ title: 'Venom (gratis)', value: 'venom' },
{ title: 'Baileys (gratis)', value: 'bailey' },
{ title: 'Baileys (gratis)', value: 'baileys' },
{ title: 'Twilio', value: 'twilio' },
{ title: 'API Oficial (Meta)', value: 'meta' },
],

View File

@@ -0,0 +1,7 @@
{
"dependencies": {
"@adiwajshing/baileys": "5.0.0",
"mime-types": "2.1.35",
"wa-sticker-formatter": "4.3.2"
}
}

View File

@@ -0,0 +1,3 @@
{
"dependencies": {}
}

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"twilio": "3.84.0"
}
}

View File

@@ -0,0 +1,6 @@
{
"dependencies": {
"venom-bot": "4.3.7",
"mime-types": "2.1.35"
}
}

View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"whatsapp-web.js": "1.18.4"
}
}

131
scripts/checker.js Normal file
View File

@@ -0,0 +1,131 @@
const { execFile } = require('node:child_process')
const { readFileSync, writeFileSync, readdirSync } = require('node:fs')
const { join } = require('path')
const process = require('node:process')
const util = require('node:util')
const semver = require('semver')
const cmd = util.promisify(execFile)
const OS_ENVIROMENT_WIN = process.platform.includes('win32')
const PATH_PACKAGES = join(__dirname, '..', `packages`)
const PATH_STARTERS = join(__dirname, '..', `starters`, `apps`)
const NPM_COMMAND = OS_ENVIROMENT_WIN ? 'npm.cmd' : 'npm'
const [PKG_NAME] = process.argv.slice(2) || [null]
/**
* Revisar ultima version de una paquetes
* @param {*} pkgName
*/
const checkPkg = async (pkgName = '') => {
const { stdout } = await cmd(
NPM_COMMAND,
['show', `${pkgName}`, 'version'],
{
stdio: 'inherit',
}
)
return stdout.trim().replace('\n', '')
}
/**
* Revisar todas las dependencias del provider
* @param {*} provider
* @returns
*/
const checkEveryProvider = async (provider = '') => {
const pkgDependencies = readFileSync(
join(PATH_PACKAGES, 'provider', 'src', provider, 'package.json')
)
try {
const { dependencies } = JSON.parse(pkgDependencies)
const devParse = Object.entries(dependencies)
const newDevParse = {}
for (const [pkgName] of devParse) {
const lastVersion = await checkPkg(pkgName)
newDevParse[pkgName] = lastVersion
}
return newDevParse
} catch (e) {
console.log(e)
return {}
}
}
/**
* Actualizar depedencias con nuevas versiones
* @param {*} provider
* @param {*} list
* @returns
*/
const updateDependencies = async (provider = '', list = {}) => {
const pathProvider = join(
PATH_PACKAGES,
'provider',
'src',
provider,
'package.json'
)
try {
const pkgDependencies = readFileSync(pathProvider)
const { dependencies } = JSON.parse(pkgDependencies)
writeFileSync(
pathProvider,
JSON.stringify(
{ dependencies: { ...dependencies, ...list } },
null,
2
)
)
} catch (e) {
console.log(e)
return {}
}
}
/**
* Actualizar starters
* @param {*} provider
* @returns
*/
const updateStarters = async (provider = '', updateDev = {}) => {
provider = provider === 'web-whatsapp' ? 'wweb' : provider
const allStarters = readdirSync(PATH_STARTERS).filter((n) =>
n.includes(provider)
)
try {
for (const base of allStarters) {
const pkgDependenciesBase = readFileSync(
join(PATH_STARTERS, base, 'package.json')
)
const pkgBase = JSON.parse(pkgDependenciesBase)
writeFileSync(
join(PATH_STARTERS, base, 'package.json'),
JSON.stringify(
{
...pkgBase,
dependencies: { ...pkgBase.dependencies, ...updateDev },
},
null,
2
)
)
}
} catch (e) {
console.log(e)
return
}
}
const main = async () => {
if (PKG_NAME) {
const list = await checkEveryProvider(PKG_NAME)
await updateDependencies(PKG_NAME, list)
await updateStarters(PKG_NAME, list)
}
}
main()

View File

@@ -4,7 +4,7 @@
"description": "",
"main": "app.js",
"scripts": {
"pre-copy": "cd .. && yarn run copy.lib base-bailey-memory",
"pre-copy": "cd .. && yarn run copy.lib base-baileys-memory",
"start": "node app.js"
},
"keywords": [],
@@ -13,9 +13,9 @@
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@adiwajshing/baileys": "^4.4.0",
"mime-types": "^2.1.35",
"wa-sticker-formatter": "^4.3.2"
"@adiwajshing/baileys": "5.0.0",
"mime-types": "2.1.35",
"wa-sticker-formatter": "4.3.2"
},
"author": "",
"license": "ISC"

View File

@@ -4,7 +4,7 @@
"description": "",
"main": "app.js",
"scripts": {
"pre-copy": "cd .. && yarn run copy.lib base-bailey-mongo",
"pre-copy": "cd .. && yarn run copy.lib base-baileys-mongo",
"start": "node app.js"
},
"keywords": [],
@@ -13,10 +13,10 @@
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@adiwajshing/baileys": "^4.4.0",
"mime-types": "^2.1.35",
"@adiwajshing/baileys": "5.0.0",
"mime-types": "2.1.35",
"mongodb": "^4.12.1",
"wa-sticker-formatter": "^4.3.2"
"wa-sticker-formatter": "4.3.2"
},
"author": "",
"license": "ISC"

View File

@@ -4,7 +4,7 @@
"description": "",
"main": "app.js",
"scripts": {
"pre-copy": "cd .. && yarn run copy.lib base-bailey-mysql",
"pre-copy": "cd .. && yarn run copy.lib base-baileys-mysql",
"start": "node app.js"
},
"keywords": [],
@@ -13,10 +13,10 @@
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"@adiwajshing/baileys": "^4.4.0",
"mime-types": "^2.1.35",
"@adiwajshing/baileys": "5.0.0",
"mime-types": "2.1.35",
"mysql2": "^2.3.3",
"wa-sticker-formatter": "^4.3.2"
"wa-sticker-formatter": "4.3.2"
},
"author": "",
"license": "ISC"

View File

@@ -11,7 +11,7 @@
"dependencies": {
"body-parser": "^1.20.1",
"polka": "^0.5.2",
"twilio": "^3.83.4",
"twilio": "3.84.0",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",

View File

@@ -11,7 +11,7 @@
"dependencies": {
"body-parser": "^1.20.1",
"polka": "^0.5.2",
"twilio": "^3.83.4",
"twilio": "3.84.0",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",

View File

@@ -11,7 +11,7 @@
"dependencies": {
"body-parser": "^1.20.1",
"polka": "^0.5.2",
"twilio": "^3.83.4",
"twilio": "3.84.0",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",

View File

@@ -9,11 +9,12 @@
},
"keywords": [],
"dependencies": {
"venom-bot": "^4.3.7",
"venom-bot": "4.3.7",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest"
"@bot-whatsapp/provider": "latest",
"mime-types": "2.1.35"
},
"author": "",
"license": "ISC"

View File

@@ -9,12 +9,12 @@
},
"keywords": [],
"dependencies": {
"venom-bot": "^4.3.7",
"venom-bot": "4.3.7",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"mime-types": "^2.1.35",
"mime-types": "2.1.35",
"mongodb": "^4.12.1"
},
"author": "",

View File

@@ -9,12 +9,13 @@
},
"keywords": [],
"dependencies": {
"venom-bot": "^4.3.7",
"venom-bot": "4.3.7",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest",
"mysql2": "^2.3.3"
"mysql2": "^2.3.3",
"mime-types": "2.1.35"
},
"author": "",
"license": "ISC"

View File

@@ -9,11 +9,11 @@
},
"keywords": [],
"dependencies": {
"whatsapp-web.js": "^1.18.4",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",
"@bot-whatsapp/provider": "latest"
"@bot-whatsapp/provider": "latest",
"whatsapp-web.js": "1.18.4"
},
"author": "",
"license": "ISC"

View File

@@ -9,7 +9,7 @@
},
"keywords": [],
"dependencies": {
"whatsapp-web.js": "^1.18.4",
"whatsapp-web.js": "1.18.4",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",

View File

@@ -9,7 +9,7 @@
},
"keywords": [],
"dependencies": {
"whatsapp-web.js": "^1.18.4",
"whatsapp-web.js": "1.18.4",
"@bot-whatsapp/bot": "latest",
"@bot-whatsapp/cli": "latest",
"@bot-whatsapp/database": "latest",