Skip to content

fix(ci): Dependabot auto-merge arms with a token whose merges run CI on main - #585

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/584-automerge-token
Oct 6, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/584-automerge-token

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Fixes #584.

⚠️ Merge order: secret first

This switches the auto-merge step to secrets.AUTOMERGE_TOKEN, which does not exist yet. If this merges first, the next Dependabot PR's auto-merge step fails red. That's loud and deliberate (see below), but it's still avoidable. Set the secret first; I'll do that with gh once the token exists.

Change

dependabot-automerge.yml armed gh pr merge --auto with the workflow's own GITHUB_TOKEN. GitHub creates no workflow run for events made with that token, and an auto-merge is attributed to the token that armed it. So #555, #564, #577 and #582 all reached main with no ci.yml and no Security Scan run, while main read green from the last human merge.

The merge step now takes secrets.AUTOMERGE_TOKEN: a fine-grained token, this repository only, with Contents, Pull requests and Workflows: read/write. Workflows is required, because Dependabot bumps pinned actions under .github/workflows/ and GitHub refuses those merges without it. fetch-metadata keeps GITHUB_TOKEN, since it only reads.

There is no || secrets.GITHUB_TOKEN fallback, deliberately. A fallback keeps auto-merge working by quietly reopening #584, and "it still merges" is exactly how the gap went unnoticed. A missing secret fails the step red on the PR instead.

The workflow's header now records this as cause 6 in its list, so nobody simplifies it back.

Test

TestDependabotAutoMergeUsesATokenWhosePushesRunCI (internal/config/dependabot_automerge_test.go), built on the shared jobSteps accessor. Five mutations, each failing with the expected message:

Mutation Fails at
GITHUB_TOKEN restored wrong-token check
AUTOMERGE_TOKEN || GITHUB_TOKEN fallback wrong-token check
extra GH_TOKEN: secrets.GITHUB_TOKEN (gh reads GH_TOKEN first) wrong-token check, on GH_TOKEN
token line removed no-token check
merge step gone exactly-one floor

The constant holding the expected expression is named mergeIdentityExpr rather than …Token, because gosec G101 flags any string constant whose name contains "token" as a hardcoded credential.

Done when (from #584)

The next Dependabot auto-merge produces a ci.yml push run on its merge commit: gh run list --workflow=ci.yml --commit=<sha> returns a run. A green main alone does not count.

🤖 Generated with Claude Code

…on main (#584)

dependabot-automerge.yml armed `gh pr merge --auto` with the workflow's own
GITHUB_TOKEN. GitHub creates no workflow run for an event made with that
token, and an auto-merge is attributed to the token that armed it, so every
Dependabot merge reached main with no ci.yml and no Security Scan run on it:
#555, #564, #577 and #582. main still read green, because its status is its
latest run and that was the last merge a person made.

The merge step now takes secrets.AUTOMERGE_TOKEN, a fine-grained token scoped
to this repository with Contents, Pull requests and Workflows read/write.
Workflows is needed because Dependabot bumps the actions pinned under
.github/workflows/ and GitHub refuses those merges without it. There is no
fallback to GITHUB_TOKEN: it would keep auto-merge working by quietly
reopening the gap, so a missing secret fails the step red on the PR instead.

TestDependabotAutoMergeUsesATokenWhosePushesRunCI pins it. Verified by five
mutations, each failing with the expected message: GITHUB_TOKEN restored, an
|| fallback, a GH_TOKEN override (gh reads GH_TOKEN first), the token removed,
and the merge step gone (the exactly-one floor).
@scttfrdmn
scttfrdmn merged commit 8fd6cb9 into main Oct 6, 2026
42 checks passed
@scttfrdmn
scttfrdmn deleted the fix/584-automerge-token branch October 6, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dependabot auto-merged commits get no CI run on main: GITHUB_TOKEN pushes don't trigger workflows

1 participant