Skip to content

Clean up pr-build/* branches for closed PRs on trunk pushes#1321

Open
jkmassel wants to merge 1 commit intotrunkfrom
jkmassel/cleanup-pr-build-branches
Open

Clean up pr-build/* branches for closed PRs on trunk pushes#1321
jkmassel wants to merge 1 commit intotrunkfrom
jkmassel/cleanup-pr-build-branches

Conversation

@jkmassel
Copy link
Copy Markdown
Contributor

@jkmassel jkmassel commented May 5, 2026

Description

Each PR build creates a pr-build/<PR#> branch via fastlane publish_pr_xcframework so 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 is closed (covers both merged and rejected — GitHub collapses them).

Changes

  • .buildkite/cleanup-pr-build-branches.sh (new): guards on BUILDKITE_BRANCH == "trunk", sources use-bot-for-git, enumerates via git ls-remote --heads origin 'refs/heads/pr-build/*', queries GET /repos/automattic/wordpress-rs/pulls/<n> with GITHUB_TOKEN, and deletes closed-PR refs with batched git 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 to build.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

  • First trunk merge after this lands sweeps the ~118 existing orphans
  • Subsequent trunk merges delete the just-merged PR's pr-build/<n> branch
  • Step is skipped on PR builds and on release builds (NEW_VERSION set)
  • Open-PR pr-build/* branches are left alone
  • If GitHub returns non-200 for a PR (deleted, rate-limit, transient), the corresponding branch is preserved and the step continues

Changelog

  • No CHANGELOG.md entry — CI-only change with no user-visible impact.

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.
@wpmobilebot
Copy link
Copy Markdown
Collaborator

⚠️ CHANGELOG.md was not updated in this PR.

Every PR should add an entry under the ## [Unreleased] section of CHANGELOG.md describing the change for our users. The format follows Keep a Changelog 1.0.0 — use one of:

  • ### Added — for new features
  • ### Changed — for changes in existing functionality (prefix **BREAKING:** if breaking)
  • ### Deprecated — for soon-to-be-removed features
  • ### Removed — for now-removed features
  • ### Fixed — for any bug fixes
  • ### Security — for vulnerability fixes

If the change genuinely has no user-visible impact (e.g. CI-only tweaks, internal refactors), add a short entry under ### Changed noting that.

@wpmobilebot
Copy link
Copy Markdown
Collaborator

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1321")

Built from 0520d27

mapfile -t branches < <(
git ls-remote --heads origin 'refs/heads/pr-build/*' \
| awk '{print $2}' \
| sed 's|^refs/heads/||'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants