fix: improve auto-merge in update-version workflow
Changes: - Use GH_PAT (if available) for better permissions - Extract PR number for more reliable merge command - Add detailed error logging with exit codes - Attempt auto-merge on existing PRs - Provide clear troubleshooting guidance This should help diagnose why auto-merge is failing and potentially fix permission issues if a GH_PAT secret is configured. https://claude.ai/code/session_015R3U3kiprQiNTTNNt31Sg6
This commit is contained in:
@@ -112,7 +112,7 @@ jobs:
|
||||
- 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 }}
|
||||
GH_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
BRANCH_NAME="update-version/stable"
|
||||
FORCE="${{ inputs.force }}"
|
||||
@@ -168,18 +168,34 @@ jobs:
|
||||
if [ $PR_CREATE_EXIT -eq 0 ]; then
|
||||
echo "✅ PR created successfully: $PR_URL"
|
||||
|
||||
# Extract PR number from URL
|
||||
PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$')
|
||||
echo "📋 PR Number: #$PR_NUMBER"
|
||||
|
||||
# Auto-merge the PR (squash merge)
|
||||
# Note: This requires branch protection rules to be satisfied
|
||||
# If checks haven't completed yet, auto-merge will queue the merge
|
||||
echo "Attempting to enable auto-merge..."
|
||||
if gh pr merge "$BRANCH_NAME" --squash --auto --delete-branch 2>/dev/null; then
|
||||
set +e
|
||||
MERGE_OUTPUT=$(gh pr merge "$PR_NUMBER" --squash --auto --delete-branch 2>&1)
|
||||
MERGE_EXIT=$?
|
||||
set -e
|
||||
|
||||
if [ $MERGE_EXIT -eq 0 ]; then
|
||||
echo "✅ Auto-merge enabled - PR will merge automatically when checks pass"
|
||||
echo "$MERGE_OUTPUT"
|
||||
else
|
||||
echo "⚠️ Auto-merge not available - PR created for manual review"
|
||||
echo "This may happen if:"
|
||||
echo "⚠️ Auto-merge failed with exit code $MERGE_EXIT"
|
||||
echo "Output: $MERGE_OUTPUT"
|
||||
echo ""
|
||||
echo "Possible reasons:"
|
||||
echo " - Required status checks haven't completed yet"
|
||||
echo " - Branch protection rules require manual approval"
|
||||
echo " - Insufficient permissions (see workflow permissions comment)"
|
||||
echo " - Insufficient permissions (try adding GH_PAT secret with repo scope)"
|
||||
echo " - Auto-merge feature not enabled in repository settings"
|
||||
echo ""
|
||||
echo "💡 Consider creating a Personal Access Token (PAT) with 'repo' scope"
|
||||
echo " and adding it as a repository secret named 'GH_PAT'"
|
||||
fi
|
||||
else
|
||||
# PR creation failed - could be duplicate or other error
|
||||
@@ -191,6 +207,15 @@ jobs:
|
||||
if [ -n "$EXISTING_PR" ]; then
|
||||
echo "ℹ️ PR already exists for branch $BRANCH_NAME"
|
||||
echo "$EXISTING_PR"
|
||||
|
||||
# Try to enable auto-merge on existing PR
|
||||
PR_NUMBER=$(echo "$EXISTING_PR" | grep -oP '^\d+')
|
||||
if [ -n "$PR_NUMBER" ]; then
|
||||
echo "Attempting to enable auto-merge on existing PR #$PR_NUMBER..."
|
||||
set +e
|
||||
gh pr merge "$PR_NUMBER" --squash --auto --delete-branch 2>&1
|
||||
set -e
|
||||
fi
|
||||
else
|
||||
echo "❌ PR creation failed with error:"
|
||||
echo "$PR_URL"
|
||||
|
||||
Reference in New Issue
Block a user