|
| 1 | +name: Branch Cleanup Preview |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + months: |
| 7 | + description: 'Delete branches older than N months (preview only)' |
| 8 | + required: true |
| 9 | + default: '24' |
| 10 | + |
| 11 | +jobs: |
| 12 | + preview-branch-deletion: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: List branches older than N months (preview) |
| 21 | + env: |
| 22 | + MONTHS: ${{ github.event.inputs.months }} |
| 23 | + run: | |
| 24 | + set -e |
| 25 | + echo "Preview: Branches older than $MONTHS months (excluding master, release, Localize, Localization branches):" |
| 26 | + cutoff=$(date -d "-$MONTHS months" +%s) |
| 27 | + total=0 |
| 28 | + preserved=0 |
| 29 | + cleanup=0 |
| 30 | + remain=0 |
| 31 | + preserved_list=() |
| 32 | + cleanup_list=() |
| 33 | + remain_list=() |
| 34 | + # List all remote branches |
| 35 | + while read branch date; do |
| 36 | + total=$((total+1)) |
| 37 | + bname=${branch#origin/} |
| 38 | + # Preserved branches |
| 39 | + if [[ "$bname" == "master" ]] || [[ "$bname" == release* ]] || [[ "$bname" == Localize* ]] || [[ "$bname" == Localization* ]]; then |
| 40 | + preserved=$((preserved+1)) |
| 41 | + preserved_list+=("$bname") |
| 42 | + continue |
| 43 | + fi |
| 44 | + # Branches to cleanup |
| 45 | + if [[ $date -lt $cutoff ]]; then |
| 46 | + cleanup=$((cleanup+1)) |
| 47 | + cleanup_list+=("$bname") |
| 48 | + else |
| 49 | + remain=$((remain+1)) |
| 50 | + remain_list+=("$bname") |
| 51 | + fi |
| 52 | + done < <(git for-each-ref --format='%(refname:short) %(committerdate:unix)' refs/remotes/) |
| 53 | + echo "Total branches: $total" |
| 54 | + echo "Preserved branches (master, release*, Localize*, Localization*): $preserved" |
| 55 | + echo "Branches to cleanup (older than $MONTHS months): $cleanup" |
| 56 | + echo "Branches that will remain: $remain" |
| 57 | + echo "---" |
| 58 | + echo "Branches to cleanup:" |
| 59 | + for b in "${cleanup_list[@]}"; do echo "$b"; done |
| 60 | + echo "---" |
0 commit comments