Skip to content

Prune GitHub Environments left behind by PR envs - #69

Merged
hamishfagg merged 1 commit into
mainfrom
feat/prune-pr-environments
Sep 29, 2026
Merged

hamishfagg merged 1 commit into
mainfrom
feat/prune-pr-environments

Conversation

@hamishfagg

Copy link
Copy Markdown
Contributor

Each anchor repo's deploy job runs in a pr-<repo>-<N> GitHub Environment. GitHub creates these on first use and never removes them, so 456 have piled up across the seven anchor repos.

prune-pr-environments.yml runs hourly and deletes each environment whose PR is closed or no longer carries the deploy label. That is the same test the PR-env ApplicationSet uses. It uses a release-train App token downscoped to Actions read, Environments write, and Pull requests read on the anchor repos only. Other environments (dev, staging, prod, and so on) never match the name pattern. If a repo's PR list can't be read, nothing in that repo is deleted.

Before merge: the release-train App needs Environments: write added, and must be installed on all seven anchor repos. Until then the token mint fails and the notify job reports it.

Verified with a dry run against the live repos using read-only access. It found 237 stale in auth, 98 in mindshub_frontend, 58 in cowork-server, 49 in cowork, 10 in mindshub_stafftools, 3 in mindshub_inference, and 1 in mindshub_services. Every env backing an open deploy PR was kept. Tests: 8 new, 237 passed in total.

Run it once by hand with dry_run after the App change, then without it to clear the backlog.

🤖 Generated with Claude Code

Each anchor repo's deploy job runs in a pr-<repo>-<N> GitHub Environment,
which GitHub creates on first use and never removes. An hourly job now
deletes the ones whose PR is closed or no longer carries the deploy
label, the same test the PR-env ApplicationSet applies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hamishfagg
hamishfagg requested a review from a team September 29, 2026 01:09
@hamishfagg
hamishfagg merged commit d6698bf into main Sep 29, 2026
6 checks passed
@hamishfagg
hamishfagg deleted the feat/prune-pr-environments branch September 29, 2026 01:24
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.

2 participants