Repository navigation
fix(ci): Dependabot auto-merge arms with a token whose merges run CI on main - #585
Merged
Merged
Conversation
…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).
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #584.
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 withghonce the token exists.Change
dependabot-automerge.ymlarmedgh pr merge --autowith the workflow's ownGITHUB_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 reachedmainwith noci.ymland noSecurity Scanrun, whilemainread 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-metadatakeepsGITHUB_TOKEN, since it only reads.There is no
|| secrets.GITHUB_TOKENfallback, 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 sharedjobStepsaccessor. Five mutations, each failing with the expected message:GITHUB_TOKENrestoredAUTOMERGE_TOKEN || GITHUB_TOKENfallbackGH_TOKEN: secrets.GITHUB_TOKEN(gh readsGH_TOKENfirst)GH_TOKENThe constant holding the expected expression is named
mergeIdentityExprrather 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.ymlpush run on its merge commit:gh run list --workflow=ci.yml --commit=<sha>returns a run. A greenmainalone does not count.🤖 Generated with Claude Code