|
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. |
4 | 8 | # |
5 | 9 | # SECURITY: This workflow uses pull_request_target which runs with base branch |
6 | 10 | # permissions. NEVER add an actions/checkout step here. |
@@ -32,12 +36,24 @@ jobs: |
32 | 36 | PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
33 | 37 | REPO: ${{ github.repository }} |
34 | 38 | 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 |
35 | 44 | PERMISSION=$(gh api "repos/$REPO/collaborators/$PR_AUTHOR/permission" --jq '.permission' 2>/dev/null || echo "none") |
36 | 45 | echo "permission=$PERMISSION" >> "$GITHUB_OUTPUT" |
37 | 46 |
|
38 | | - - name: Auto-approve PR |
| 47 | + - name: Auto-approve (collaborator) |
39 | 48 | if: steps.check-permission.outputs.permission == 'admin' || steps.check-permission.outputs.permission == 'write' |
40 | 49 | env: |
41 | 50 | PR_URL: ${{ github.event.pull_request.html_url }} |
42 | 51 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
43 | 52 | 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