Skip to content

ci: the janitor also cancels a closed PR's merge-group runs - #412

Closed
jonit-dev wants to merge 1 commit into
developfrom
ci/janitor-merge-groups
Closed

jonit-dev wants to merge 1 commit into
developfrom
ci/janitor-merge-groups

Conversation

@jonit-dev

Copy link
Copy Markdown
Contributor

Closing or admin-merging a PR drops it from the develop merge queue, but the merge-group run GitHub already started keeps going — run 37093098790 held 9 self-hosted jobs for #404 after #404 merged, and the janitor only ever swept the head ref, which never names that branch.

The cancel job now also sweeps queued/in-progress runs whose branch starts with gh-readonly-queue/${BASE_REF}/pr-${PR_NUMBER}-, built from the event through env: and filtered in jq off one gh run list --json databaseId,status,headBranch --limit 100. Fork, develop/main-head and self-run guards unchanged.

Evidence: the janitor case in scripts/__tests__/ci-structure.spec.ts pins the env-built prefix and the startswith filter — red on the old workflow (1 failed), green on the new one (182 passed with ci-efficiency.spec.ts); pnpm lint clean; the step shell smoke-tested against a stub gh cancelled both of PR 404's group runs and spared a completed run, a main group, another PR's group and its own run id.

Dequeueing, admin-merging or closing a pull request drops it from the
develop merge queue but does not cancel the merge-group run GitHub
already started, so that run keeps holding self-hosted runners for a
verdict nothing will read: run 37093098790 ran 9 jobs for #404 after #404
had merged. The janitor only swept the head ref, which never names that
branch.

It now also cancels queued and in-progress runs whose branch starts with
`gh-readonly-queue/<base>/pr-<number>-`, built from the event's own base
ref and PR number through `env:` — no `github.*` context reaches the shell
— and filtered in jq off one `gh run list --json
databaseId,status,headBranch --limit 100`. The fork, develop/main-head and
self-run guards are unchanged.

Evidence:
- `pnpm exec vitest run scripts/__tests__/ci-structure.spec.ts
  scripts/__tests__/ci-efficiency.spec.ts` — the janitor case now pins
  the env-built prefix and the `startswith` filter: red on the old
  workflow (1 failed | 134 skipped), green on the new one (182 passed).
- `pnpm lint` clean.
- The step's shell, extracted and run against a stub `gh`, cancelled the
  head ref's in-progress run plus both of PR 404's queued/in-progress
  merge-group runs, and spared a completed run, a `main`-based group,
  another PR's group, `pr-4040` and the janitor's own run id.
@jonit-dev
jonit-dev enabled auto-merge October 3, 2026 05:02
@jonit-dev

Copy link
Copy Markdown
Contributor Author

Folded into #409 (one PR for the CI follow-ups).

@jonit-dev jonit-dev closed this Oct 3, 2026
auto-merge was automatically disabled October 3, 2026 05:13

Pull request was closed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant