Files
InfiniteAPI/.github/workflows/update-version.yml
T
Claude 1fa321c0a2 fix(ci): correct Yarn 4 cache paths and add auto-merge for version PRs
- Fixed cache paths for Yarn 4 (node_modules + .yarn/install-state.gz)
- Updated all workflows to use actions/cache@v4
- Added auto-merge for WhatsApp version update PRs

https://claude.ai/code/session_01QPt4WssG6jjEciQKdVpFtK
2026-02-02 18:20:03 +00:00

188 lines
6.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: Update WhatsApp Version
on:
schedule:
# Run daily at 06:00 UTC (when WhatsApp typically deploys updates)
- cron: '0 6 * * *'
workflow_dispatch:
inputs:
force:
description: 'Force create PR even if version unchanged (useful for re-triggering)'
required: false
default: 'false'
type: boolean
permissions:
contents: write
pull-requests: write
jobs:
update-version:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Setup Node and Corepack
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Enable Corepack and Set Yarn Version
run: |
corepack enable
corepack prepare yarn@4.x --activate
- name: Configure Git for HTTPS
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Force git to use HTTPS instead of SSH for GitHub repositories
git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
git config --global url."https://github.com/".insteadOf "git@github.com:"
# Configure git to use GITHUB_TOKEN for authentication
git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
- name: Restore Yarn Cache
uses: actions/cache@v4
id: yarn-cache
with:
path: |
node_modules
.yarn/install-state.gz
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: |
# Run the update script, capture exit code
# Exit codes: 0=success, 1=error, 2=fetch failed (fallback used)
set +e
yarn update:version
EXIT_CODE=$?
set -e
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
# Only fail on fatal errors (exit code 1)
if [ $EXIT_CODE -eq 1 ]; then
echo "::error::Script failed with fatal error"
exit 1
fi
# Exit code 2 means fetch failed but fallback was used - this is a warning
if [ $EXIT_CODE -eq 2 ]; then
echo "::warning::Could not fetch latest version from WhatsApp servers"
fi
- name: Check for changes
id: check_changes
run: |
FORCE="${{ inputs.force }}"
if git diff --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
if [ "$FORCE" == "true" ]; then
echo "force_mode=true" >> $GITHUB_OUTPUT
echo "::notice::Force mode enabled - will create PR even without changes"
else
echo "force_mode=false" >> $GITHUB_OUTPUT
fi
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "force_mode=false" >> $GITHUB_OUTPUT
fi
- name: Create Pull Request
if: steps.check_changes.outputs.has_changes == 'true' || steps.check_changes.outputs.force_mode == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME="update-version/stable"
FORCE="${{ inputs.force }}"
# 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
git checkout -b "$BRANCH_NAME"
# Only add the single source of truth file
git add src/Defaults/baileys-version.json
# Create commit (allow empty if force mode)
if [ "$FORCE" == "true" ] && git diff --cached --quiet; then
git commit --allow-empty -m "chore: force WhatsApp Web version check"
else
git commit -m "chore: update WhatsApp Web version"
fi
git push origin "$BRANCH_NAME"
# Create PR using GitHub CLI
PR_BODY="Automated WhatsApp Web version update.
This PR updates the WhatsApp Web client revision to the latest version fetched from \`web.whatsapp.com\`.
**Single source of truth:**
- \`src/Defaults/baileys-version.json\` (other files import from here)
**Update frequency:** Daily at 06:00 UTC"
if [ "$FORCE" == "true" ]; then
PR_BODY="$PR_BODY
> **Note:** This PR was created with force mode enabled."
fi
# Create PR
PR_URL=$(gh pr create \
--title "chore: update WhatsApp Web version" \
--body "$PR_BODY" \
--base master \
--head "$BRANCH_NAME" 2>&1) || true
if [[ "$PR_URL" == *"github.com"* ]]; then
echo "PR created: $PR_URL"
# Auto-merge the PR (squash merge)
echo "Attempting to auto-merge..."
gh pr merge "$BRANCH_NAME" --squash --auto --delete-branch || \
gh pr merge "$BRANCH_NAME" --squash --delete-branch || \
echo "Auto-merge not available - PR created for manual review"
else
echo "PR already exists or could not be created: $PR_URL"
fi
- name: Summary
run: |
echo "### WhatsApp Version Update" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
EXIT_CODE="${{ steps.update_version.outputs.exit_code }}"
HAS_CHANGES="${{ steps.check_changes.outputs.has_changes }}"
FORCE_MODE="${{ steps.check_changes.outputs.force_mode }}"
if [ "$EXIT_CODE" == "2" ]; then
echo "⚠️ Warning: Could not fetch latest version from WhatsApp servers" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
if [ "$HAS_CHANGES" == "true" ]; then
echo "✅ New version detected and PR created" >> $GITHUB_STEP_SUMMARY
elif [ "$FORCE_MODE" == "true" ]; then
echo "🔄 Force mode: PR created (no version change)" >> $GITHUB_STEP_SUMMARY
else
echo "️ Already up to date" >> $GITHUB_STEP_SUMMARY
fi