-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25af322
commit fe101bc
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Cleanup Stale Branches | ||
|
||
on: | ||
schedule: | ||
# Runs at 00:00 every day | ||
- cron: "0 0 * * *" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
delete_old_branches: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Fetch all branches | ||
run: git fetch --all | ||
|
||
- name: Delete stale branches | ||
run: | | ||
# Get the date 7 days ago in YYYY-MM-DD format | ||
seven_days_ago=$(date -d '7 days ago' +%Y-%m-%d) | ||
# List branches that haven't been updated in the last 7 days | ||
for branch in $(git for-each-ref --format='%(refname:short) %(committerdate:short)' refs/remotes/origin | awk -v date="$seven_days_ago" '$2 <= date {print $1}'); do | ||
# Ensure the branch is not 'main', 'master', or any protected branches | ||
if [[ "$branch" != "origin/main" && "$branch" != "origin/master" && "$branch" != *"HEAD"* ]]; then | ||
git push origin --delete ${branch#origin/} | ||
echo "Deleted branch $branch" | ||
fi | ||
done | ||
- name: Cleanup | ||
run: git remote prune origin |
This file contains 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