Skip to content

fix: author hotfix resolution PR with trigger-capable state token#205

Merged
joshua-temple merged 1 commit into
mainfrom
fix/hotfix-pr-create-token
Jun 17, 2026
Merged

fix: author hotfix resolution PR with trigger-capable state token#205
joshua-temple merged 1 commit into
mainfrom
fix/hotfix-pr-create-token

Conversation

@joshua-temple

Copy link
Copy Markdown
Collaborator

Problem

On a protected env branch requiring a status check, the generated hotfix flow deadlocks. The apply job opens the resolution PR with gh pr create under the job-level GH_TOKEN, which defaulted to GITHUB_TOKEN. A PR authored by github-actions[bot] does not fire on: pull_request workflows, so the env-branch required check could only post via on: workflow_run after the hotfix run finished. The apply job does not finish until the PR merges, the PR cannot merge until the check posts, and the check cannot post until the apply job finishes.

Fix

Set the apply job's job-level GH_TOKEN to the configured state token (config.GetStateToken()) so the resolution PR is authored by a trigger-capable actor. on: pull_request then fires and the required check posts on PR open, independent of the apply job. The existing poll-until-mergeable merge step still gates the merge on that check, so it remains genuinely gating. When no state token is configured the token degrades to GITHUB_TOKEN; post-hotfix automation then requires a configured state_token, consistent with the merge step's existing caveat.

internal/generate/hotfix.go: apply-job env GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} -> GH_TOKEN: <getStateTokenRef()>. The clean-path merge step keeps its own state-token env unchanged.

Verification

  • New failing-first unit tests in internal/generate/hotfix_test.go assert the apply job authors the PR under the state token (state-token configured) and degrades to GITHUB_TOKEN otherwise. Red before, green after.
  • go build ./..., go test ./... (1403 tests), golangci-lint run ./... all green. e2e module builds and vets clean. The bot-PR trigger suppression is a real-GitHub behavior the local harness cannot reproduce, so coverage rests on the generator assertion plus the live fleet re-run.

The hotfix apply job opened the resolution PR with gh pr create under the
job-level GH_TOKEN, which defaulted to GITHUB_TOKEN. A PR authored by
github-actions[bot] does not fire on: pull_request workflows, so on a
protected env branch the required status check could only post via
on: workflow_run after the hotfix run finished. The apply job would not
finish until the PR merged, the PR could not merge until the check posted,
and the check could not post until the apply job finished: a deadlock.

Set the apply job's job-level GH_TOKEN to the configured state token so
the resolution PR is authored by a trigger-capable actor. on: pull_request
then fires and the env-branch required check posts on PR open, independent
of the apply job, while the poll-until-mergeable merge step still gates the
merge on that check. When no state token is configured the token degrades
to GITHUB_TOKEN; post-hotfix automation then requires a configured
state_token, consistent with the merge step.

Signed-off-by: Joshua Temple <joshua.temple@stablekernel.com>
@joshua-temple joshua-temple merged commit a1b11d1 into main Jun 17, 2026
7 checks passed
@joshua-temple joshua-temple deleted the fix/hotfix-pr-create-token branch June 17, 2026 14:08
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.

1 participant