Rename cleanup workflow and add stale branch pruning - #8089
Merged
Conversation
|
Co-authored-by: jonrohan <54012+jonrohan@users.noreply.github.com>
Co-authored-by: jonrohan <54012+jonrohan@users.noreply.github.com>
Co-authored-by: jonrohan <54012+jonrohan@users.noreply.github.com>
jonrohan
reviewed
Jun 29, 2026
Co-authored-by: jonrohan <54012+jonrohan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Rename scheduled cleanup workflow and add stale branch cleanup
Rename cleanup workflow and add stale branch pruning
Jun 29, 2026
jonrohan
marked this pull request as ready for review
June 29, 2026 23:39
Contributor
There was a problem hiding this comment.
Pull request overview
This PR renames the scheduled preview-environment cleanup workflow to a more general cleanup workflow and extends it with automated pruning of stale branches.
Changes:
- Renamed workflow file and workflow name (from
environmentstocleanup) while keeping the environment cleanup script logic intact. - Added a new
branchesjob that enumerates branches, skips default/protected branches, and deletes branches based on PR state and/or commit age. - Added per-branch logging and a workflow summary table for branch cleanup outcomes.
Show a summary per file
| File | Description |
|---|---|
| .github/workflows/environment.yml | Removed the old scheduled environment cleanup workflow. |
| .github/workflows/cleanup.yml | Added the renamed workflow plus a new branches job for stale branch pruning and workflow summaries. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 3
- Review effort level: Low
Comment on lines
+209
to
+232
| if (pull && pull.state !== 'open') { | ||
| reason = `pr-${pull.state}`; | ||
| core.info(`Removing ${branch.name} since ${pull.html_url} is ${pull.state}`); | ||
|
|
||
| try { | ||
| await github.rest.git.deleteRef({ | ||
| owner, | ||
| repo, | ||
| ref: `heads/${branch.name}`, | ||
| }); | ||
| type = 'removed'; | ||
| } catch (error) { | ||
| reason = `${reason}-delete-failed`; | ||
| core.warning(`Failed to remove ${branch.name}: ${getErrorMessage(error)}`); | ||
| } | ||
|
|
||
| changes.push({ | ||
| branch, | ||
| pull, | ||
| reason, | ||
| type, | ||
| }); | ||
| continue; | ||
| } |
Comment on lines
+199
to
+207
| const { data: pulls } = await github.rest.pulls.list({ | ||
| owner, | ||
| repo, | ||
| head: `${owner}:${branch.name}`, | ||
| state: 'all', | ||
| per_page: 1, | ||
| }); | ||
|
|
||
| pull = pulls[0]; |
Comment on lines
+234
to
+238
| const { data: commit } = await github.rest.repos.getCommit({ | ||
| owner, | ||
| repo, | ||
| ref: branch.commit.sha, | ||
| }); |
jonrohan
approved these changes
Jun 29, 2026
joshblack
approved these changes
Jun 30, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 30, 2026
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.
The scheduled cleanup workflow now covers both preview-environment cleanup and stale branch cleanup. It keeps the existing environment behavior intact while adding automated branch deletion for closed-PR branches and branches with no activity in the last 6 months.
Changelog
New
branchesjob to the scheduled cleanup workflow.open, orChanged
.github/workflows/environment.ymlto.github/workflows/cleanup.yml.environmentstocleanup.deployments: writecontents: writeRemoved
.github/workflows/environment.ymlworkflow file.Rollout strategy
CI/workflow-only change; no published package impact.
Testing & Reviewing
.github/workflows/cleanup.ymlas a rename plus one new job.Merge checklist