Repository navigation
ci: preserve *-maintenance branches when merging PRs - #243
Merged
Merged
Conversation
GitHub's repo-wide "Automatically delete head branches" setting cannot exclude long-lived release branches by pattern, so enabling it would delete branches like `0.19-maintenance` the moment a cherry-pick PR lands on `main`. Replace it with a workflow that deletes the head branch on PR merge unless the branch name ends in `-maintenance`. The repo setting must be disabled for this workflow to be authoritative; otherwise it races the workflow for non-maintenance branches. GitHub deletes via REST return 422 when the ref is already gone (manual delete, prior run, or another workflow); we treat that as success so re-runs and races stay green. Cross-repo (fork) PRs are skipped because GitHub cannot delete branches in a fork's repository anyway. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
|
🤖 News Fragment Check ✅ Success! This PR meets the news fragment requirements. |
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces a GitHub Actions workflow to delete merged PR head branches while preserving long-lived *-maintenance branches, replacing GitHub’s repo-wide “Automatically delete head branches” setting.
Changes:
- Adds a
pull_request_target: closedworkflow that deletes the head branch after merge when the PR comes from the same repo. - Skips deletion for branches whose names end with
-maintenance. - Makes deletion re-runnable by treating “already deleted” as a successful outcome.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address review feedback on #243: - Replace the broad `endsWith('-maintenance')` job filter with a precise `^[0-9]{1,3}\.[0-9]{1,3}-maintenance$` check in the script. GitHub Actions expressions lack regex support, so the tightened check has to live in `run:` instead of the job-level `if:`. This prevents an unrelated branch like `foo-maintenance` from being spared accidentally. - Restrict the "already deleted" tolerance to responses that contain both `HTTP 422` and `Reference does not exist`, instead of any substring `not found`. The previous match swallowed unrelated 404s (wrong repo, missing permission, bad API path) and left the merged branch undeleted while the workflow reported success. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
whme
commented
May 23, 2026
The header comment said this workflow preserves `*-maintenance` branches, but the active check matches only `<major>.<minor>-maintenance` with 1-3 digit components. Tighten the wording so the documentation matches the regex on line 51. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.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.
Summary
Automatically delete head branchessetting with a workflow that skips<major>.<minor>-maintenancebranches (1-3 digit version components, e.g.0.19-maintenance), so long-lived release branches are not deleted when a cherry-pick PR merges intomain.pull_request_target: closed, only whenmerged == trueand the head and base repo match (forks are skipped since GitHub cannot delete branches in a fork's repo).422 Reference does not existas success so re-runs and races with manual deletes stay green; persistent failures surface as a red job.Important
The repo setting Settings -> General -> Automatically delete head branches must be disabled for this workflow to be the single source of truth. Otherwise the setting wins for non-maintenance branches and races this workflow.
Test plan
Automatically delete head branchessetting before merging this PR.ci/preserve-maintenance-branches-on-merge) and confirm the workflow runs and the branch is deleted afterwards.0.19-maintenance->maincherry-pick PR and confirm0.19-maintenanceis still present after merge.