4e0a4a1dd2
Updated the workflow to include dynamic run names and improved commit messages and PR body formatting.
204 lines
7.6 KiB
YAML
204 lines
7.6 KiB
YAML
name: Update WAProto
|
||
|
||
on:
|
||
schedule:
|
||
- cron: '0 3 * * *'
|
||
workflow_dispatch:
|
||
|
||
# Dynamic run name with run number
|
||
run-name: "Update WAProto #${{ github.run_number }}"
|
||
|
||
permissions:
|
||
contents: write
|
||
pull-requests: write
|
||
actions: write
|
||
|
||
jobs:
|
||
update-proto:
|
||
runs-on: ubuntu-latest
|
||
timeout-minutes: 10
|
||
|
||
steps:
|
||
- uses: actions/checkout@v3
|
||
|
||
- name: Install Node
|
||
uses: actions/setup-node@v3
|
||
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: Install packages
|
||
run: |
|
||
yarn install --immutable
|
||
yarn --cwd proto-extract install --immutable
|
||
|
||
- name: Update WAProto.proto
|
||
id: wa_proto_info
|
||
run: |
|
||
yarn --cwd proto-extract start > wa-logs.txt
|
||
WA_VERSION=$(cat wa-logs.txt | perl -n -e'/Current version\: (.+)/ && print $1')
|
||
WA_JS_URL=$(cat wa-logs.txt | perl -n -e'/Found source JS URL\: (.+)/ && print $1')
|
||
echo "wa_version=$WA_VERSION" >> $GITHUB_OUTPUT
|
||
echo "wa_js_url=$WA_JS_URL" >> $GITHUB_OUTPUT
|
||
|
||
# Display version prominently
|
||
echo "📱 WhatsApp Proto Version: v$WA_VERSION"
|
||
echo "🔗 Source JS URL: $WA_JS_URL"
|
||
|
||
- name: GenerateStatics
|
||
run: yarn gen:protobuf
|
||
|
||
- name: Update baileys-version.json
|
||
run: |
|
||
WA_VERSION="${{steps.wa_proto_info.outputs.wa_version}}"
|
||
WA_NUMBERS=$(echo $WA_VERSION | sed "s/\./, /g")
|
||
echo -e "{\n\t\"version\": [$WA_NUMBERS]\n}" > src/Defaults/baileys-version.json
|
||
|
||
# Confirm update
|
||
echo "✅ Updated baileys-version.json to v$WA_VERSION"
|
||
cat src/Defaults/baileys-version.json
|
||
|
||
- name: Create Pull Request
|
||
id: create_pr
|
||
uses: peter-evans/create-pull-request@v5
|
||
with:
|
||
commit-message: 'chore: update proto/version to v${{steps.wa_proto_info.outputs.wa_version}}'
|
||
title: 'chore: update WhatsApp proto to v${{steps.wa_proto_info.outputs.wa_version}}'
|
||
branch: 'update-proto/stable'
|
||
delete-branch: true
|
||
labels: 'update-proto'
|
||
body: |
|
||
## 📦 Automated WhatsApp Proto Update
|
||
|
||
**Version:** `v${{steps.wa_proto_info.outputs.wa_version}}`
|
||
|
||
**Source JS URL:** ${{steps.wa_proto_info.outputs.wa_js_url}}
|
||
|
||
### Changes
|
||
- ✅ Updated `WAProto/*` (protobuf definitions)
|
||
- ✅ Updated `src/Defaults/baileys-version.json`
|
||
|
||
### Update Frequency
|
||
Daily at 03:00 UTC (00:00 BRT)
|
||
add-paths: |
|
||
WAProto/*
|
||
src/Defaults/baileys-version.json
|
||
|
||
- name: Auto-merge PR
|
||
if: steps.create_pr.outputs.pull-request-number != ''
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
|
||
run: |
|
||
PR_NUMBER="${{ steps.create_pr.outputs.pull-request-number }}"
|
||
WA_VERSION="${{ steps.wa_proto_info.outputs.wa_version }}"
|
||
|
||
echo "🔀 Attempting to merge PR #$PR_NUMBER (v$WA_VERSION) via squash..."
|
||
|
||
# Check PR status
|
||
set +e
|
||
PR_STATE=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json state --jq '.state' 2>&1)
|
||
PR_VIEW_EXIT=$?
|
||
set -e
|
||
|
||
if [ $PR_VIEW_EXIT -ne 0 ] || [ -z "$PR_STATE" ]; then
|
||
echo "⚠️ Could not retrieve PR state, attempting merge anyway..."
|
||
else
|
||
echo "📊 PR State: $PR_STATE"
|
||
if [ "$PR_STATE" != "OPEN" ]; then
|
||
echo "⚠️ PR is not open (state: $PR_STATE), skipping merge"
|
||
exit 0
|
||
fi
|
||
fi
|
||
|
||
# Brief wait for GitHub to compute PR mergeability
|
||
sleep 5
|
||
|
||
# Check if PR is mergeable
|
||
set +e
|
||
MERGEABLE=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json mergeable --jq '.mergeable' 2>&1)
|
||
set -e
|
||
echo "📊 Mergeable: $MERGEABLE"
|
||
|
||
# Attempt merge with error handling
|
||
set +e
|
||
MERGE_OUTPUT=$(gh pr merge "$PR_NUMBER" \
|
||
--repo "${{ github.repository }}" \
|
||
--squash \
|
||
--delete-branch \
|
||
--yes 2>&1)
|
||
MERGE_EXIT=$?
|
||
set -e
|
||
|
||
if [ $MERGE_EXIT -eq 0 ]; then
|
||
echo "✅ PR #$PR_NUMBER (v$WA_VERSION) merged successfully"
|
||
echo "$MERGE_OUTPUT"
|
||
else
|
||
echo "::warning::Standard merge failed for PR #$PR_NUMBER (v$WA_VERSION)"
|
||
echo "::group::Merge Error Output"
|
||
echo "$MERGE_OUTPUT"
|
||
echo "::endgroup::"
|
||
|
||
# Try with admin flag (bypasses branch protection if user has admin rights)
|
||
echo "🔧 Attempting merge with admin override..."
|
||
set +e
|
||
ADMIN_OUTPUT=$(gh pr merge "$PR_NUMBER" \
|
||
--repo "${{ github.repository }}" \
|
||
--squash \
|
||
--delete-branch \
|
||
--admin 2>&1)
|
||
ADMIN_EXIT=$?
|
||
set -e
|
||
|
||
if [ $ADMIN_EXIT -eq 0 ]; then
|
||
echo "✅ PR #$PR_NUMBER (v$WA_VERSION) merged successfully with admin override"
|
||
echo "$ADMIN_OUTPUT"
|
||
else
|
||
echo "::error::Failed to merge PR #$PR_NUMBER (v$WA_VERSION) even with admin override"
|
||
echo "::group::Admin Merge Error Output"
|
||
echo "$ADMIN_OUTPUT"
|
||
echo "::endgroup::"
|
||
echo "::warning::Consider configuring a Personal Access Token (PAT) with full repo permissions as GH_PAT secret"
|
||
echo "::warning::PR #$PR_NUMBER was created but requires manual merge: https://github.com/${{ github.repository }}/pull/$PR_NUMBER"
|
||
# Don't exit with error to avoid blocking the workflow
|
||
exit 0
|
||
fi
|
||
fi
|
||
|
||
- name: Summary
|
||
run: |
|
||
echo "### 📦 WAProto Update" >> $GITHUB_STEP_SUMMARY
|
||
echo "" >> $GITHUB_STEP_SUMMARY
|
||
|
||
WA_VERSION="${{ steps.wa_proto_info.outputs.wa_version }}"
|
||
WA_JS_URL="${{ steps.wa_proto_info.outputs.wa_js_url }}"
|
||
PR_NUMBER="${{ steps.create_pr.outputs.pull-request-number }}"
|
||
|
||
echo "**Version:** \`v$WA_VERSION\`" >> $GITHUB_STEP_SUMMARY
|
||
echo "" >> $GITHUB_STEP_SUMMARY
|
||
|
||
if [ -n "$PR_NUMBER" ]; then
|
||
echo "✅ **PR #$PR_NUMBER created and merged successfully**" >> $GITHUB_STEP_SUMMARY
|
||
echo "" >> $GITHUB_STEP_SUMMARY
|
||
echo "**Changes:**" >> $GITHUB_STEP_SUMMARY
|
||
echo "- 📦 Updated WAProto/* (protobuf definitions)" >> $GITHUB_STEP_SUMMARY
|
||
echo "- 📝 Updated baileys-version.json" >> $GITHUB_STEP_SUMMARY
|
||
echo "" >> $GITHUB_STEP_SUMMARY
|
||
echo "**Source:** [$WA_JS_URL]($WA_JS_URL)" >> $GITHUB_STEP_SUMMARY
|
||
else
|
||
echo "ℹ️ No changes detected - already up to date" >> $GITHUB_STEP_SUMMARY
|
||
fi
|