Skip to content

Commit 16d3d07

Browse files
committed
Use WORKFLOW_PAT where appropriate to ensure auto-merge can be applied
1 parent 02060e9 commit 16d3d07

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

.github/workflows/dependabot-auto-merge.yaml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,10 @@ jobs:
5757
if: steps.pr.outputs.author == 'dependabot[bot]' && steps.pr.outputs.base_ref == 'main'
5858
shell: bash
5959
run: |
60-
# Attempt to enable auto-merge. The gh CLI doesn't provide structured error codes,
61-
# so we must parse error messages. Common expected errors:
62-
# - "auto-merge is already enabled" - auto-merge was already set
63-
# - "not authorized for this protected branch" - branch protection requirements not yet met
64-
# NOTE: This typically occurs when the GITHUB_TOKEN doesn't have sufficient permissions.
65-
# For workflows triggered by Dependabot PRs, the token has restricted permissions even
66-
# with contents:write and pull-requests:write. Solutions include:
67-
# 1. Use a GitHub App token (most secure)
68-
# 2. Use a PAT stored in secrets (simpler but less secure)
69-
# 3. Use pull_request_target trigger (has security implications)
70-
# - "Required status checks" - waiting for CI checks to pass
71-
# - "Required approving review" - waiting for approval
7260
set -o pipefail
7361
if ! gh pr merge --auto --merge "${{ steps.pr.outputs.number }}" --repo "${{ github.repository }}" 2>&1 | tee /tmp/gh-output.txt; then
74-
if grep -qE "auto-merge is already enabled|not authorized for this protected branch|[Rr]equired.*status.*check|[Rr]equired approving review|[Rr]equired.*review" /tmp/gh-output.txt; then
62+
if grep -qE "auto-merge is already enabled|[Rr]equired.*status.*check|[Rr]equired approving review|[Rr]equired.*review" /tmp/gh-output.txt; then
7563
echo "Auto-merge not enabled yet - this is expected when requirements are not met or already enabled"
76-
if grep -q "not authorized for this protected branch" /tmp/gh-output.txt; then
77-
echo ""
78-
echo "NOTE: The 'not authorized for this protected branch' error typically means:"
79-
echo " - The GITHUB_TOKEN has restricted permissions when triggered by Dependabot PRs"
80-
echo " - To fix this, consider using a GitHub App token or PAT with appropriate permissions"
81-
echo " - See workflow comments for more details"
82-
fi
8364
exit 0
8465
else
8566
echo "Unexpected error enabling auto-merge:"
@@ -88,4 +69,4 @@ jobs:
8869
fi
8970
fi
9071
env:
91-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
GH_TOKEN: ${{ secrets.WORKFLOW_PAT }}

0 commit comments

Comments
 (0)