From 62f2fac641214af1aac36ba6289c6b908de58044 Mon Sep 17 00:00:00 2001 From: Renato Alcara Date: Wed, 18 Feb 2026 20:13:10 -0300 Subject: [PATCH] Update update-proto.yml --- .github/workflows/update-proto.yml | 155 +++++++++++++++++++---------- 1 file changed, 100 insertions(+), 55 deletions(-) diff --git a/.github/workflows/update-proto.yml b/.github/workflows/update-proto.yml index 021b8e51..4dda3707 100644 --- a/.github/workflows/update-proto.yml +++ b/.github/workflows/update-proto.yml @@ -66,7 +66,7 @@ jobs: 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 + echo "{\"version\": [$WA_NUMBERS]}" > src/Defaults/baileys-version.json # Confirm update echo "✅ Updated baileys-version.json to v$WA_VERSION" @@ -98,7 +98,7 @@ jobs: WAProto/* src/Defaults/baileys-version.json - - name: Auto-merge PR + - name: Enable Auto-merge if: steps.create_pr.outputs.pull-request-number != '' env: GH_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }} @@ -106,79 +106,122 @@ jobs: 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..." + echo "🔀 Enabling auto-merge for PR #$PR_NUMBER (v$WA_VERSION)..." - # Check PR status + # Enable auto-merge with squash method 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" \ + AUTO_MERGE_OUTPUT=$(gh pr merge "$PR_NUMBER" \ --repo "${{ github.repository }}" \ --squash \ - --delete-branch \ - --yes 2>&1) - MERGE_EXIT=$? + --auto \ + --delete-branch 2>&1) + AUTO_MERGE_EXIT=$? set -e - if [ $MERGE_EXIT -eq 0 ]; then - echo "✅ PR #$PR_NUMBER (v$WA_VERSION) merged successfully" - echo "$MERGE_OUTPUT" + if [ $AUTO_MERGE_EXIT -eq 0 ]; then + echo "✅ Auto-merge enabled for PR #$PR_NUMBER (v$WA_VERSION)" + echo "$AUTO_MERGE_OUTPUT" + echo "âŗ PR will be merged automatically once all checks pass" else - echo "::warning::Standard merge failed for PR #$PR_NUMBER (v$WA_VERSION)" - echo "::group::Merge Error Output" - echo "$MERGE_OUTPUT" + echo "::warning::Failed to enable auto-merge for PR #$PR_NUMBER (v$WA_VERSION)" + echo "::group::Auto-merge Error Output" + echo "$AUTO_MERGE_OUTPUT" echo "::endgroup::" - # Try with admin flag (bypasses branch protection if user has admin rights) - echo "🔧 Attempting merge with admin override..." + # Fall back to waiting for checks and then merging + echo "🔄 Falling back to wait-and-merge strategy..." + + # Wait for checks to start + echo "âŗ Waiting 30 seconds for checks to start..." + sleep 30 + + # Wait for checks to complete (max 5 minutes) + echo "âŗ Waiting for checks to complete..." + WAIT_COUNT=0 + MAX_WAIT=60 # 60 * 5 seconds = 5 minutes + + while [ $WAIT_COUNT -lt $MAX_WAIT ]; do + set +e + CHECK_STATUS=$(gh pr checks "$PR_NUMBER" --repo "${{ github.repository }}" 2>&1) + CHECK_EXIT=$? + set -e + + if [ $CHECK_EXIT -eq 0 ]; then + echo "📊 Current check status:" + echo "$CHECK_STATUS" + + # Check if all checks passed + if echo "$CHECK_STATUS" | grep -q "All checks have passed"; then + echo "✅ All checks passed!" + break + fi + + # Check if any check failed + if echo "$CHECK_STATUS" | grep -qE "(fail|failure|error)"; then + echo "❌ Some checks failed, aborting merge" + exit 1 + fi + fi + + WAIT_COUNT=$((WAIT_COUNT + 1)) + echo "âŗ Waiting... ($WAIT_COUNT/$MAX_WAIT)" + sleep 5 + done + + if [ $WAIT_COUNT -ge $MAX_WAIT ]; then + echo "::warning::Timeout waiting for checks to complete" + echo "::warning::PR #$PR_NUMBER requires manual merge: https://github.com/${{ github.repository }}/pull/$PR_NUMBER" + exit 0 + fi + + # Try to merge now that checks passed + echo "🔀 Attempting to merge PR #$PR_NUMBER..." set +e - ADMIN_OUTPUT=$(gh pr merge "$PR_NUMBER" \ + MERGE_OUTPUT=$(gh pr merge "$PR_NUMBER" \ --repo "${{ github.repository }}" \ --squash \ --delete-branch \ - --admin 2>&1) - ADMIN_EXIT=$? + --yes 2>&1) + MERGE_EXIT=$? set -e - if [ $ADMIN_EXIT -eq 0 ]; then - echo "✅ PR #$PR_NUMBER (v$WA_VERSION) merged successfully with admin override" - echo "$ADMIN_OUTPUT" + if [ $MERGE_EXIT -eq 0 ]; then + echo "✅ PR #$PR_NUMBER (v$WA_VERSION) merged successfully" + echo "$MERGE_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 "::error::Failed to merge PR #$PR_NUMBER (v$WA_VERSION)" + echo "::group::Merge Error Output" + echo "$MERGE_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 + + # Try with admin flag + 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 with admin override" + echo "$ADMIN_OUTPUT" + else + echo "::error::Failed to merge 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 requires manual merge: https://github.com/${{ github.repository }}/pull/$PR_NUMBER" + exit 0 + fi fi fi - name: Summary + if: always() run: | echo "### đŸ“Ļ WAProto Update" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY @@ -191,13 +234,15 @@ jobs: echo "" >> $GITHUB_STEP_SUMMARY if [ -n "$PR_NUMBER" ]; then - echo "✅ **PR #$PR_NUMBER created and merged successfully**" >> $GITHUB_STEP_SUMMARY + echo "✅ **PR #$PR_NUMBER created with auto-merge enabled**" >> $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 + echo "" >> $GITHUB_STEP_SUMMARY + echo "🔀 PR will merge automatically once checks pass" >> $GITHUB_STEP_SUMMARY else echo "â„šī¸ No changes detected - already up to date" >> $GITHUB_STEP_SUMMARY fi