Skip to content

Add stale branch cleanup workflow and lifecycle policy#15680

Merged
HariniMalothu17 merged 4 commits intomicrosoft:mainfrom
HariniMalothu17:main
Feb 24, 2026
Merged

Add stale branch cleanup workflow and lifecycle policy#15680
HariniMalothu17 merged 4 commits intomicrosoft:mainfrom
HariniMalothu17:main

Conversation

@HariniMalothu17
Copy link
Copy Markdown
Contributor

@HariniMalothu17 HariniMalothu17 commented Feb 20, 2026

Description

Introduces a GitHub Action to automatically clean up stale branches and a documentation page outlining the branch lifecycle policy.

Changes

  • cleanup-stale-branches.yml

  • Scheduled to run every Monday at 08:00 UTC

  • Can also be triggered manually with a dry-run option for previewing

  • Two-tier staleness thresholds:

copilot/* branches: 90 days
All other branches: 180 days
Protected branches (never deleted):
main, master, develop
release/, hotfix/, archive/*
-stable (e.g., 0.72-stable, 0.80-stable)
preview-
(e.g., preview-0.80-test)

  • Skips branches with open PRs (including drafts)

  • If you need to keep a branch from being deleted, Rename it under archive/

  • branch-lifecycle-policy.md

Documents the cleanup policy, thresholds, and protected patterns
Explains how to preserve a branch from cleanup
FAQ for common questions

Motivation
The repository has accumulated many stale branches over time. This workflow helps maintain a clean branch list by automatically removing inactive branches while protecting important ones (stable releases, previews, branches with open PRs).

Testing
Ran the workflow manually in dry-run mode — completed successfully in 20s
Verified protected branch patterns against existing repo branches

Type of Change

  • Automation (AI changes or Github Actions to reduce effort of manual tasks)

Resolves #15034

Microsoft Reviewers: Open in CodeFlow

@HariniMalothu17 HariniMalothu17 requested review from a team as code owners February 20, 2026 10:02
@vineethkuttan
Copy link
Copy Markdown
Contributor

I believe you tested these changes in your fork. Also confirm once that it is not deleting any protected branches.

Don't Merge this PR on Monday.

@vineethkuttan
Copy link
Copy Markdown
Contributor

image

I tested this in my fork and confirmed that we can list all branches, that's good.
After the PR is merged, identify all stale branches.
Once the list is verified, we can proceed with deletion.
However, a fully automated approach seems risky; a manually triggered pipeline would provide greater control.

What is your view @iamAbhi-916

@iamAbhi-916
Copy link
Copy Markdown
Contributor

iamAbhi-916 commented Feb 24, 2026

image I tested this in my fork and confirmed that we can list all branches, that's good. After the PR is merged, identify all stale branches. Once the list is verified, we can proceed with deletion. However, a fully automated approach seems risky; a manually triggered pipeline would provide greater control.

What is your view @iamAbhi-916

yeah, we should have a manual trigger, but we are deleting for 90-days of inactivity so this should be okay

Copy link
Copy Markdown
Contributor

@iamAbhi-916 iamAbhi-916 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HariniMalothu17
Copy link
Copy Markdown
Contributor Author

HariniMalothu17 commented Feb 24, 2026

image I tested this in my fork and confirmed that we can list all branches, that's good. After the PR is merged, identify all stale branches. Once the list is verified, we can proceed with deletion. However, a fully automated approach seems risky; a manually triggered pipeline would provide greater control.

What is your view @iamAbhi-916

Monday run will not delete any branches
DRY_RUN="${{ github.event_name == 'schedule' && 'true' || inputs.dry_run }}"

@HariniMalothu17 HariniMalothu17 merged commit 01816e9 into microsoft:main Feb 24, 2026
30 checks passed
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.

To Implement Repository Branch Lifecycle Policy

3 participants