Update update-version.yml

This commit is contained in:
Renato Alcara
2026-02-19 09:38:48 -03:00
committed by GitHub
parent fe66257a0f
commit c40e6e506e
+55 -100
View File
@@ -210,130 +210,85 @@ jobs:
fi
fi
- name: Enable Auto-merge
- name: Auto-merge PR
if: steps.create_pr.outputs.pr_number != ''
env:
GH_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER="${{ steps.create_pr.outputs.pr_number }}"
VERSION="${{ steps.update_version.outputs.version }}"
echo "🔀 Attempting to merge PR #$PR_NUMBER via squash..."
echo "🔀 Enabling auto-merge for PR #$PR_NUMBER (v$VERSION)..."
# Enable auto-merge with squash method
# Check PR status
set +e
AUTO_MERGE_OUTPUT=$(gh pr merge "$PR_NUMBER" \
--repo "${{ github.repository }}" \
--squash \
--auto \
--delete-branch 2>&1)
AUTO_MERGE_EXIT=$?
PR_STATE=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json state --jq '.state' 2>&1)
PR_VIEW_EXIT=$?
set -e
if [ $AUTO_MERGE_EXIT -eq 0 ]; then
echo "✅ Auto-merge enabled for PR #$PR_NUMBER (v$VERSION)"
echo "$AUTO_MERGE_OUTPUT"
echo "⏳ PR will be merged automatically once all checks pass"
if [ $PR_VIEW_EXIT -ne 0 ] || [ -z "$PR_STATE" ]; then
echo "⚠️ Could not retrieve PR state, attempting merge anyway..."
else
echo "::warning::Failed to enable auto-merge for PR #$PR_NUMBER (v$VERSION)"
echo "::group::Auto-merge Error Output"
echo "$AUTO_MERGE_OUTPUT"
echo "::endgroup::"
# 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"
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 merged successfully"
echo "$MERGE_OUTPUT"
else
echo "::warning::Standard merge failed for PR #$PR_NUMBER"
echo "::group::Merge Error Output"
echo "$MERGE_OUTPUT"
echo "::endgroup::"
# Try to merge now that checks passed
echo "🔀 Attempting to merge PR #$PR_NUMBER..."
# Try with admin flag (bypasses branch protection if user has admin rights)
echo "🔧 Attempting merge with admin override..."
set +e
MERGE_OUTPUT=$(gh pr merge "$PR_NUMBER" \
ADMIN_OUTPUT=$(gh pr merge "$PR_NUMBER" \
--repo "${{ github.repository }}" \
--squash \
--delete-branch \
--yes 2>&1)
MERGE_EXIT=$?
--admin 2>&1)
ADMIN_EXIT=$?
set -e
if [ $MERGE_EXIT -eq 0 ]; then
echo "✅ PR #$PR_NUMBER (v$VERSION) merged successfully"
echo "$MERGE_OUTPUT"
if [ $ADMIN_EXIT -eq 0 ]; then
echo "✅ PR #$PR_NUMBER merged successfully with admin override"
echo "$ADMIN_OUTPUT"
else
echo "::error::Failed to merge PR #$PR_NUMBER (v$VERSION)"
echo "::group::Merge Error Output"
echo "$MERGE_OUTPUT"
echo "::error::Failed to merge PR #$PR_NUMBER even with admin override"
echo "::group::Admin Merge Error Output"
echo "$ADMIN_OUTPUT"
echo "::endgroup::"
# 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$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
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
if: always()
run: |
echo "### WhatsApp Version Update" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
@@ -352,7 +307,7 @@ jobs:
fi
if [ "$HAS_CHANGES" == "true" ]; then
echo "✅ New version detected and PR created with auto-merge" >> $GITHUB_STEP_SUMMARY
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