Clean up pr-build/* branches for closed PRs on trunk pushes#1321
Open
Clean up pr-build/* branches for closed PRs on trunk pushes#1321
pr-build/* branches for closed PRs on trunk pushes#1321Conversation
Adds a Buildkite step that runs on every trunk push, enumerates `pr-build/<n>` refs via `git ls-remote`, queries each associated PR's state through the GitHub REST API, and deletes refs whose PR is closed (merged or rejected). Skips branches we couldn't verify (non-200 response). The first run will sweep ~118 orphans accumulated since `pr-build/*` was introduced; subsequent runs clean up the just-merged PR's branch in the same build.
Collaborator
|
Every PR should add an entry under the
If the change genuinely has no user-visible impact (e.g. CI-only tweaks, internal refactors), add a short entry under |
Collaborator
XCFramework BuildThis PR's XCFramework is available for testing. Add to your .package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1321")Built from 0520d27 |
crazytonyli
approved these changes
May 6, 2026
| mapfile -t branches < <( | ||
| git ls-remote --heads origin 'refs/heads/pr-build/*' \ | ||
| | awk '{print $2}' \ | ||
| | sed 's|^refs/heads/||' |
Contributor
There was a problem hiding this comment.
I'm not sure if those branches are all fetched during the CI checkout. Using GH API (like the PR state check) probably would be more robust.
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.
Description
Each PR build creates a
pr-build/<PR#>branch viafastlane publish_pr_xcframeworkso the iOS apps can pull the snapshot xcframework. Nothing prunes these afterwards, so they accumulate — there are 118 of them on origin today, most for long-merged PRs.This adds a Buildkite step that runs on every trunk push, lists the
pr-build/*refs, asks GitHub for each PR's state, and deletes the refs whose PR isclosed(covers both merged and rejected — GitHub collapses them).Changes
.buildkite/cleanup-pr-build-branches.sh(new): guards onBUILDKITE_BRANCH == "trunk", sourcesuse-bot-for-git, enumerates viagit ls-remote --heads origin 'refs/heads/pr-build/*', queriesGET /repos/automattic/wordpress-rs/pulls/<n>withGITHUB_TOKEN, and deletes closed-PR refs with batchedgit push origin :refs/heads/...(chunks of 50). Skips on non-200 responses so we never delete a ref we couldn't verify..buildkite/pipeline.yml: new top-level step gated tobuild.branch == "trunk" && build.env("NEW_VERSION") == null(skips release builds, matching the publish-trunk-xcframework gate). Default agent queue, like the other git+API helper steps (validate-changelog.sh).Test plan
pr-build/<n>branchNEW_VERSIONset)pr-build/*branches are left aloneChangelog
CHANGELOG.mdentry — CI-only change with no user-visible impact.