department-of-veterans-affairs / va.gov-team

Public resources for building on and in support of VA.gov. Visit complete Knowledge Hub:
https://depo-platform-documentation.scrollhelp.site/index.html
284 stars 206 forks source link

[Maintenance] Automation for Cleaning Up Stale GitHub Branches #30081

Open dginther opened 3 years ago

dginther commented 3 years ago

The Problem

A number of our GitHub repositories have stale branches. These branches can present problems, specifically w/ Jenkins when repository scans occur. Each branch corresponds to at least 1 GH API request. These branches also correspond to disk space on our jenkins

More Context

This is a postmortem action item from an outage incurred when our GitHub API limit was exhausted. https://github.com/department-of-veterans-affairs/va.gov-team-sensitive/pull/305

Work to be Done

Acceptance Criteria

jbritt1 commented 2 years ago

I personally would propose that the automated solution target and purge branches over 90 days of age. One could argue that considering the speed at which development often moves, 90 day old branches are typically long and far behind current work / initiatives / etc.

jbritt1 commented 2 years ago

My proposal for the solution would be (if possible) a github action that leverages the GitHub API to find and delete all branches in all repos we touch over 90 days of age. I could also see expanding it to 6 months at first and then tweak / reduce from there.

jbritt1 commented 2 years ago

Perhaps something along the lines of the discussion seen here: https://stackoverflow.com/questions/10325599/delete-all-branches-that-are-more-than-x-days-weeks-old/49998249