Skip to content

ci: prune pr-build/* branches for closed PRs on trunk pushes#496

Closed
jkmassel wants to merge 1 commit intotrunkfrom
jkmassel/cleanup-pr-builds
Closed

ci: prune pr-build/* branches for closed PRs on trunk pushes#496
jkmassel wants to merge 1 commit intotrunkfrom
jkmassel/cleanup-pr-builds

Conversation

@jkmassel
Copy link
Copy Markdown
Contributor

@jkmassel jkmassel commented May 5, 2026

Summary

  • Each PR build force-pushes a pr-build/<n> snapshot branch (ci(ios): publish + prune per-PR XCFramework snapshot branches #495). Nothing prunes them, so they accumulate.
  • Adds a Buildkite step on every trunk push that lists pr-build/* refs, queries each PR's state via the GitHub API, and deletes the refs whose PR is closed (covers both merged and rejected — GitHub collapses them).
  • Mirrors Automattic/wordpress-rs#1321, which paired with the equivalent publish PR there.

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/wordpress-mobile/GutenbergKit/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 step gated to build.branch == "trunk", sharing the standard *plugins anchor (CI toolkit + NVM).

Test plan

  • First trunk merge after this lands sweeps any orphan pr-build/* branches accumulated from ci(ios): publish + prune per-PR XCFramework snapshot branches #495 testing.
  • Subsequent trunk merges delete the just-merged PR's pr-build/<n> branch.
  • Step is skipped on PR builds.
  • Open-PR pr-build/* branches are left alone.
  • If GitHub returns non-200 for a PR (deleted, rate-limited, transient), the corresponding branch is preserved and the step continues.

Related

Each PR build force-pushes a `pr-build/<n>` snapshot branch. Nothing
prunes them, so they accumulate. Add a Buildkite step that runs on
trunk pushes, lists `pr-build/*` refs, queries each PR's state via the
GitHub API, and deletes the refs whose PR is `closed` (covers both
merged and rejected — GitHub collapses them).

Skips a branch on any non-200 response so we never delete a ref we
couldn't verify. Mirrors the wordpress-rs sweep step.
@github-actions github-actions Bot added the [Type] Build Tooling Issues or PRs related to build tooling label May 5, 2026
@jkmassel jkmassel marked this pull request as draft May 5, 2026 23:32
@jkmassel
Copy link
Copy Markdown
Contributor Author

jkmassel commented May 5, 2026

Folded into #495 — keeping it as a single PR per @jkmassel.

@jkmassel jkmassel closed this May 5, 2026
@jkmassel jkmassel deleted the jkmassel/cleanup-pr-builds branch May 5, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant