Skip to content

Rename cleanup workflow and add stale branch pruning - #8089

Merged
jonrohan merged 6 commits into
mainfrom
copilot/rename-cleanup-workflow
Jun 30, 2026
Merged

Rename cleanup workflow and add stale branch pruning#8089
jonrohan merged 6 commits into
mainfrom
copilot/rename-cleanup-workflow

Conversation

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

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

  • Added a branches job to the scheduled cleanup workflow.
  • Branch cleanup deletes non-protected, non-default branches when either:
    • the associated PR is not open, or
    • the branch head commit is older than 6 months.
  • Added branch-level logging and a workflow summary table with action, reason, and PR link when present.
if (pull && pull.state !== 'open') {
  reason = `pr-${pull.state}`
} else if (parsedCommitDate < sixMonthsAgo) {
  reason = 'stale-6-months'
}

Changed

  • Renamed the workflow from .github/workflows/environment.yml to .github/workflows/cleanup.yml.
  • Updated the workflow name from environments to cleanup.
  • Scoped permissions per job:
    • environment cleanup keeps deployments: write
    • branch cleanup uses contents: write

Removed

  • Removed the old .github/workflows/environment.yml workflow file.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

CI/workflow-only change; no published package impact.

Testing & Reviewing

  • Review .github/workflows/cleanup.yml as a rename plus one new job.
  • Confirm the existing environment cleanup script is behaviorally unchanged.
  • Confirm branch cleanup skips the default branch and protected branches before evaluating PR state / commit age.
  • Confirm all third-party actions remain pinned to the existing SHAs.

Merge checklist

@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 488f869

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI and others added 3 commits June 29, 2026 23:34
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>
Comment thread .github/workflows/cleanup.yml Outdated
Copilot AI and others added 2 commits June 29, 2026 23:37
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
Copilot AI requested a review from jonrohan June 29, 2026 23:38
@jonrohan jonrohan added skip changeset This change does not need a changelog integration-tests: skipped manually Changes in this PR do not require an integration test labels Jun 29, 2026
@jonrohan
jonrohan marked this pull request as ready for review June 29, 2026 23:39
@jonrohan
jonrohan requested a review from a team as a code owner June 29, 2026 23:39
@jonrohan
jonrohan requested review from Copilot and joshblack June 29, 2026 23:39

Copilot AI left a comment

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.

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 environments to cleanup) while keeping the environment cleanup script logic intact.
  • Added a new branches job 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
jonrohan added this pull request to the merge queue Jun 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 30, 2026
@jonrohan
jonrohan added this pull request to the merge queue Jun 30, 2026
Merged via the queue into main with commit 8324da4 Jun 30, 2026
69 of 70 checks passed
@jonrohan
jonrohan deleted the copilot/rename-cleanup-workflow branch June 30, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: skipped manually Changes in this PR do not require an integration test skip changeset This change does not need a changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants