Skip to content

Commit

Permalink
ammend sync-with-upstream.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
in-incognito committed Aug 21, 2024
1 parent 25af322 commit fe101bc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/cleanup-branches.yml
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
6 changes: 3 additions & 3 deletions .github/workflows/sync-with-upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ jobs:
git add .github/workflows/
git commit -m "Merge upstream changes while keeping all forked workflows"
# - name: Pull Latest Changes from Origin
# if: env.changes == 'true'
# run: git pull origin main
- name: Pull Latest Changes from Origin
if: env.changes == 'true'
run: git pull origin main --rebase

- name: Push Changes
if: env.changes == 'true'
Expand Down

0 comments on commit fe101bc

Please sign in to comment.