-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: implement automated WhatsApp version update workflow and related scripts #2130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
purpshell
merged 2 commits into
WhiskeySockets:master
from
jlucaso1:add-autoupdate-version
Jan 17, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| name: Update WhatsApp Version | ||
|
|
||
| on: | ||
| schedule: | ||
| # Run on the 1st of every month at 02:00 UTC | ||
| - cron: '0 0 * * 0' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| update-version: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Setup Node and Corepack | ||
| uses: actions/setup-node@v3.6.0 | ||
| with: | ||
| node-version: 20.x | ||
|
|
||
| - name: Enable Corepack and Set Yarn Version | ||
| run: | | ||
| corepack enable | ||
| corepack prepare yarn@4.x --activate | ||
|
|
||
| - name: Restore Yarn Cache | ||
| uses: actions/cache@v3 | ||
| id: yarn-cache | ||
| with: | ||
| path: .yarn/cache | ||
| key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-yarn- | ||
|
|
||
| - name: Install packages | ||
| run: yarn install --immutable | ||
|
|
||
| - name: Update WhatsApp Web Version | ||
| id: update_version | ||
| run: yarn update:version | ||
|
|
||
| - name: Check for changes | ||
| id: check_changes | ||
| run: | | ||
| if git diff --quiet; then | ||
| echo "has_changes=false" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "has_changes=true" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: Create Pull Request | ||
| if: steps.check_changes.outputs.has_changes == 'true' | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| BRANCH_NAME="update-version/stable" | ||
|
|
||
| # Configure git | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| # Check if branch exists and delete it | ||
| git push origin --delete "$BRANCH_NAME" 2>/dev/null || true | ||
|
|
||
| # Create new branch, commit, and push | ||
| git checkout -b "$BRANCH_NAME" | ||
| git add src/Defaults/baileys-version.json src/Defaults/index.ts src/Utils/generics.ts | ||
| git commit -m "chore: update WhatsApp Web version" | ||
| git push origin "$BRANCH_NAME" | ||
|
|
||
| # Create PR using GitHub CLI | ||
| gh pr create \ | ||
| --title "chore: update WhatsApp Web version" \ | ||
| --body "Automated WhatsApp Web version update. | ||
|
|
||
| This PR updates the WhatsApp Web client revision to the latest version fetched from \`web.whatsapp.com\`. | ||
|
|
||
| **Files updated:** | ||
| - \`src/Defaults/baileys-version.json\` | ||
| - \`src/Defaults/index.ts\` | ||
| - \`src/Utils/generics.ts\`" \ | ||
| --base master \ | ||
| --head "$BRANCH_NAME" || echo "PR already exists or could not be created" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Script to update WhatsApp Web version across the codebase. | ||
| * Fetches the latest version from web.whatsapp.com and updates: | ||
| * - src/Defaults/baileys-version.json | ||
| * - src/Defaults/index.ts | ||
| * - src/Utils/generics.ts | ||
| * | ||
| * Usage: yarn update:version | ||
| */ | ||
|
|
||
| import { readFileSync, writeFileSync } from 'fs' | ||
| import { dirname, join } from 'path' | ||
| import { fileURLToPath } from 'url' | ||
| import { fetchLatestWaWebVersion } from '../src/Utils/generics.ts' | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url) | ||
| const __dirname = dirname(__filename) | ||
| const ROOT_DIR = join(__dirname, '..') | ||
|
|
||
| function updateBaileysVersionJson(version: [number, number, number]): boolean { | ||
| const filePath = join(ROOT_DIR, 'src/Defaults/baileys-version.json') | ||
| const content = { | ||
| version | ||
| } | ||
|
|
||
| try { | ||
| const currentContent = readFileSync(filePath, 'utf-8') | ||
| const currentVersion = JSON.parse(currentContent).version as number[] | ||
|
|
||
| if (currentVersion[0] === version[0] && currentVersion[1] === version[1] && currentVersion[2] === version[2]) { | ||
| console.log(`✓ baileys-version.json already up to date`) | ||
| return false | ||
| } | ||
|
|
||
| writeFileSync(filePath, JSON.stringify(content) + '\n') | ||
| console.log(`✓ Updated baileys-version.json: [${currentVersion.join(', ')}] → [${version.join(', ')}]`) | ||
| return true | ||
| } catch (error) { | ||
| console.error(`✗ Failed to update baileys-version.json:`, error) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| function updateGenerics(version: [number, number, number]): boolean { | ||
| const filePath = join(ROOT_DIR, 'src/Utils/generics.ts') | ||
|
|
||
| try { | ||
| const content = readFileSync(filePath, 'utf-8') | ||
| const versionRegex = /const baileysVersion = \[(\d+),\s*(\d+),\s*(\d+)\]/ | ||
| const match = content.match(versionRegex) | ||
|
|
||
| if (!match) { | ||
| throw new Error('Could not find baileysVersion declaration in generics.ts') | ||
| } | ||
|
|
||
| const currentVersion = [+match[1]!, +match[2]!, +match[3]!] | ||
|
|
||
| if (currentVersion[0] === version[0] && currentVersion[1] === version[1] && currentVersion[2] === version[2]) { | ||
| console.log(`✓ src/Utils/generics.ts already up to date`) | ||
| return false | ||
| } | ||
|
|
||
| const newContent = content.replace( | ||
| versionRegex, | ||
| `const baileysVersion = [${version[0]}, ${version[1]}, ${version[2]}]` | ||
| ) | ||
|
|
||
| writeFileSync(filePath, newContent) | ||
| console.log(`✓ Updated src/Utils/generics.ts: [${currentVersion.join(', ')}] → [${version.join(', ')}]`) | ||
| return true | ||
| } catch (error) { | ||
| console.error(`✗ Failed to update src/Utils/generics.ts:`, error) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| function updateIndex(version: [number, number, number]): boolean { | ||
| const filePath = join(ROOT_DIR, 'src/Defaults/index.ts') | ||
|
|
||
| try { | ||
| const content = readFileSync(filePath, 'utf-8') | ||
| const versionRegex = /const version = \[(\d+),\s*(\d+),\s*(\d+)\]/ | ||
| const match = content.match(versionRegex) | ||
|
|
||
| if (!match) { | ||
| throw new Error('Could not find version declaration in index.ts') | ||
| } | ||
|
|
||
| const currentVersion = [+match[1]!, +match[2]!, +match[3]!] | ||
|
|
||
| if (currentVersion[0] === version[0] && currentVersion[1] === version[1] && currentVersion[2] === version[2]) { | ||
| console.log(`✓ src/Defaults/index.ts already up to date`) | ||
| return false | ||
| } | ||
|
|
||
| const newContent = content.replace(versionRegex, `const version = [${version[0]}, ${version[1]}, ${version[2]}]`) | ||
|
|
||
| writeFileSync(filePath, newContent) | ||
| console.log(`✓ Updated src/Defaults/index.ts: [${currentVersion.join(', ')}] → [${version.join(', ')}]`) | ||
| return true | ||
| } catch (error) { | ||
| console.error(`✗ Failed to update src/Defaults/index.ts:`, error) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| async function main() { | ||
| console.log('Fetching latest WhatsApp Web version...\n') | ||
|
|
||
| const result = await fetchLatestWaWebVersion() | ||
|
|
||
| if (!result.isLatest) { | ||
| console.error('Failed to fetch latest version:', result.error) | ||
| process.exit(1) | ||
| } | ||
|
|
||
| console.log(`Latest version: [${result.version.join(', ')}]\n`) | ||
|
|
||
| const updates = [ | ||
| updateBaileysVersionJson(result.version), | ||
| updateGenerics(result.version), | ||
| updateIndex(result.version) | ||
| ] | ||
|
|
||
| const hasUpdates = updates.some(Boolean) | ||
|
|
||
| console.log('') | ||
| if (hasUpdates) { | ||
| console.log('Version update complete!') | ||
| // Set GitHub Actions output if running in CI | ||
| if (process.env.GITHUB_OUTPUT) { | ||
| const { appendFileSync } = await import('fs') | ||
| appendFileSync(process.env.GITHUB_OUTPUT, `updated=true\n`) | ||
| appendFileSync(process.env.GITHUB_OUTPUT, `version=${result.version.join('.')}\n`) | ||
| } | ||
| } else { | ||
| console.log('All files are already up to date.') | ||
| if (process.env.GITHUB_OUTPUT) { | ||
| const { appendFileSync } = await import('fs') | ||
| appendFileSync(process.env.GITHUB_OUTPUT, `updated=false\n`) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| main().catch(error => { | ||
| console.error('Fatal error:', error) | ||
| process.exit(1) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1 @@ | ||
| { | ||
| "version": [2, 3000, 1027934701] | ||
| } | ||
| {"version":[2,3000,1027934701]} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.