Skip to content

Commit de7124e

Browse files
philipbalinovclaude
andcommitted
fix: match on commit author instead of workflow actor
GitHub's approval gate checks the commit author, not the workflow run actor. When a bot-authored PR is merged by a human the run's actor is the human, but head_commit.author.name is still the bot. - Check head_commit.author.name instead of actor.login - Remove workflow scope restriction (all CI workflows need approval) - Remove version/ branch restriction (post-merge runs land on main) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3758e89 commit de7124e

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

.github/workflows/auto-approve-bot-runs.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
name: Auto-approve bot workflow runs
22

33
on:
4-
# Scoped to CodeQL only — the workflow that requires approval on bot PRs.
54
# workflow_run runs in the default-branch context, so it is not itself
65
# subject to the approval gate.
76
workflow_run:
8-
workflows: ["CodeQL Advanced"]
97
types: [requested]
108

119
permissions:
@@ -14,23 +12,26 @@ permissions:
1412
jobs:
1513
approve:
1614
runs-on: ubuntu-latest
15+
# GitHub's approval gate checks the *commit* author, not the workflow
16+
# actor. When a bot-authored PR is merged by a human the run's actor
17+
# is the human, but head_commit.author.name is still the bot.
1718
if: >-
18-
contains(fromJSON('["github-actions[bot]","dependabot[bot]"]'), github.event.workflow_run.actor.login) &&
19-
startsWith(github.event.workflow_run.head_branch, 'version/')
19+
contains(fromJSON('["github-actions[bot]","dependabot[bot]"]'),
20+
github.event.workflow_run.head_commit.author.name)
2021
steps:
2122
- name: Approve workflow run if pending
2223
env:
2324
GH_TOKEN: ${{ github.token }}
2425
RUN_ID: ${{ github.event.workflow_run.id }}
25-
ACTOR: ${{ github.event.workflow_run.actor.login }}
26+
AUTHOR: ${{ github.event.workflow_run.head_commit.author.name }}
2627
REPO: ${{ github.repository }}
2728
run: |
28-
# The 'requested' event fires before the conclusion is set.
29-
# Poll briefly for GitHub to settle the run into action_required.
29+
# The 'requested' event fires before the status settles.
30+
# Poll briefly for GitHub to move the run into action_required.
3031
for i in 1 2 3; do
3132
STATUS=$(gh run view "$RUN_ID" --repo "$REPO" --json status --jq '.status')
3233
if [ "$STATUS" = "action_required" ]; then
33-
echo "Approving run $RUN_ID triggered by $ACTOR"
34+
echo "Approving run $RUN_ID (commit authored by $AUTHOR)"
3435
gh run approve "$RUN_ID" --repo "$REPO"
3536
exit 0
3637
fi

0 commit comments

Comments
 (0)