Skip to content

GitHub Action to delete merged stale branches #9542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

OlufunkeMoronfolu
Copy link
Collaborator

This PR introduces a GitHub action that automates branch deletion and removes the need for authors to delete branches by themselves (as we currently do).
This action does the following

  • Automatically deletes branches merged into the development branch that are at least 14 days old
  • Branches with "backup" in the name are never deleted, regardless of their merge age or wether they have been merged into the development branch or not

Usage:
The action can be triggered in two ways:

  • Automated runs:
    • This is scheduled to run every 1st and 15th of each month
    • The deletion will only affect branches that were merged at least 14 days before the scheduled run. For instance, if the action runs on the 15th, branches merged on the 14th will not be deleted because of the 14-days rule. I added this buffer period to allow reopening branch if needed
  • Manual runs:
    • Here, the action can be triggered from the Actions tab right here on GitHub
    • Manual runs can be done in dry mode with no actual deletion by setting to true or by setting to false to delete branches
      • When set to true, it is possible to see all the branches recommend for deletion and other needed additional details. Then you can run again while setting to false to actually delete the branches
    • You can also change the minimum age of the merged branches from the default 14 to another suitable number

I am happy to discuss this further. Thanks.

PS: This logic does not consider rebasing as we do not allow rebasing for this repository.

@ConnorLand
Copy link
Collaborator

I am a little wary of monthly automated branch deletions, as it is possible that I might merge something and then need to go back to the merged branch 4 weeks later for something.

For safety, would it be possible to set PRs assigned to me as Manual delete status only?

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