Skip to content

Commit a923b8f

Browse files
committed
fix(ci): handle GITHUB_TOKEN self-approval limitation for bot PRs
- pr-quality.yml: detect bot authors and use APPROVE_TOKEN (PAT) to approve their PRs; GITHUB_TOKEN can't approve PRs created by github-actions[bot] since they share the same identity - auto-merge-deps.yml: skip approve step for github-actions[bot] PRs (would always fail with "Can not approve your own pull request")
1 parent 8a57393 commit a923b8f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

.github/workflows/auto-merge-deps.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
github-token: ${{ secrets.GITHUB_TOKEN }}
4343

4444
- name: Auto-approve PR
45+
# Skip for github-actions[bot] -- GITHUB_TOKEN can't approve
46+
# its own PRs. release-please PRs need approval from pr-quality.yml
47+
# using APPROVE_TOKEN, or manual approval.
48+
if: github.event.pull_request.user.login != 'github-actions[bot]'
4549
env:
4650
PR_URL: ${{ github.event.pull_request.html_url }}
4751
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pr-quality.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# Solo-maintainer auto-approve: approves PRs from repo collaborators
2-
# so that required_approving_review_count >= 1 (OpenSSF Scorecard) is
3-
# satisfied without manual review for trusted authors.
1+
# Solo-maintainer auto-approve: approves PRs from repo collaborators and
2+
# trusted bots so that required_approving_review_count >= 1 is satisfied
3+
# without manual review.
4+
#
5+
# For bot PRs (github-actions[bot]), GITHUB_TOKEN can't self-approve.
6+
# Set an APPROVE_TOKEN secret (PAT with repo scope) to approve bot PRs.
7+
# Without APPROVE_TOKEN, bot PRs require manual approval.
48
#
59
# SECURITY: This workflow uses pull_request_target which runs with base branch
610
# permissions. NEVER add an actions/checkout step here.
@@ -32,12 +36,24 @@ jobs:
3236
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
3337
REPO: ${{ github.repository }}
3438
run: |
39+
# Bots are trusted if they match known bot accounts
40+
if [[ "$PR_AUTHOR" == "dependabot[bot]" || "$PR_AUTHOR" == "renovate[bot]" || "$PR_AUTHOR" == "github-actions[bot]" ]]; then
41+
echo "permission=bot" >> "$GITHUB_OUTPUT"
42+
exit 0
43+
fi
3544
PERMISSION=$(gh api "repos/$REPO/collaborators/$PR_AUTHOR/permission" --jq '.permission' 2>/dev/null || echo "none")
3645
echo "permission=$PERMISSION" >> "$GITHUB_OUTPUT"
3746
38-
- name: Auto-approve PR
47+
- name: Auto-approve (collaborator)
3948
if: steps.check-permission.outputs.permission == 'admin' || steps.check-permission.outputs.permission == 'write'
4049
env:
4150
PR_URL: ${{ github.event.pull_request.html_url }}
4251
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4352
run: gh pr review --approve "$PR_URL"
53+
54+
- name: Auto-approve (bot via APPROVE_TOKEN)
55+
if: steps.check-permission.outputs.permission == 'bot' && secrets.APPROVE_TOKEN != ''
56+
env:
57+
PR_URL: ${{ github.event.pull_request.html_url }}
58+
GH_TOKEN: ${{ secrets.APPROVE_TOKEN }}
59+
run: gh pr review --approve "$PR_URL"

0 commit comments

Comments
 (0)