fix: land hotfix merge on unprotected env branches#201
Merged
Conversation
The clean cherry-pick path merged with `gh pr merge --auto`, which calls GitHub's enablePullRequestAutoMerge mutation. GitHub rejects that mutation when the target env branch has no protection rule, so the apply step exited non-zero under set -e and left the hotfix PR open on unprotected branches. Prefer auto-merge so required checks still gate the merge on protected branches, but fall back to an immediate squash merge when auto-merge cannot be enabled. The `if !` guard keeps the failing attempt from tripping set -e. Signed-off-by: Joshua Temple <joshua.temple@stablekernel.com>
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.
Problem
The generated
cascade-hotfix.yamlclean cherry-pick path merged withgh pr merge --auto --squash "$BRANCH".--autocalls GitHub'senablePullRequestAutoMergemutation, which GitHub rejects when the target env branch has no protection rule (Protected branch rules not configured for this branch). Underset -ethe step exited non-zero, the hotfix run failed, and the PR was left open. This breaks every adopter whose env branches are unprotected (branch protection is optional / plan-gated for OSS).Every other PR-merge cascade emits is a plain
gh pr merge --squash, which works unprotected. Only the hotfix path assumed protection.Fix
Prefer auto-merge so required checks still gate the merge on protected branches, but fall back to an immediate squash merge when auto-merge cannot be enabled:
--autosucceeds and waits for checks (unchanged).--autofails, fallback merges immediately. The hotfix lands either way.if !guard keeps the failing attempt from trippingset -e.The conflict-resolution path opens a PR for manual resolve and never auto-merges, so no change is needed there.
Verification
TestHotfixGenerator_CleanPathMergeFallbackasserts the guarded--autoattempt and the direct-merge fallback. Confirmed red before the change, green after.go build ./..., fullgo test ./...(1400 pass),golangci-lint run ./...(clean).TestHotfixGenerator_Actionlintruns actionlint (with shellcheck) over the regenerated workflow; the newif/then/filints clean.Note: the e2e hotfix harness reimplements apply+merge directly against gitea REST and never dispatches the generated
gh pr mergeshell, so the runnable proof of the emitted shell is the actionlint test plus the unit assertion. Live re-run on the unprotected 3env fleet to follow.