Skip to content

Commit 0bbb4f3

Browse files
committed
remove push event and dry run logic
1 parent cba0d09 commit 0bbb4f3

1 file changed

Lines changed: 1 addition & 28 deletions

File tree

.github/workflows/delete-stale-branches.yml

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,13 @@
44
#
55
# Respects protected branches and skips fork branches.
66
# Deletes all matching branches per run, oldest first.
7-
#
8-
# To test without deleting anything, trigger this workflow manually via
9-
# workflow_dispatch and leave dry-run set to "true" (the default). The
10-
# run will log "Would delete: ..." for every branch it would have removed.
117

128
name: Delete stale branches
139

1410
on:
15-
push:
16-
branches:
17-
- stale-branch-cleanup # temporary: for dry-run testing on this PR branch — remove before merging
1811
schedule:
1912
- cron: "0 4 * * *"
2013
workflow_dispatch:
21-
inputs:
22-
dry-run:
23-
description: "Dry run (log what would be deleted without deleting)"
24-
required: false
25-
default: "true"
26-
type: choice
27-
options:
28-
- "true"
29-
- "false"
3014

3115
permissions:
3216
contents: write
@@ -39,14 +23,9 @@ jobs:
3923
- name: Delete unassociated branches older than 60 days
4024
env:
4125
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42-
DRY_RUN: ${{ github.event_name == 'push' && 'true' || github.event_name == 'schedule' && 'false' || inputs.dry-run }}
4326
run: |
4427
deleted=0
4528
46-
if [ "$DRY_RUN" = "true" ]; then
47-
echo "*** DRY RUN — no branches will be deleted ***"
48-
fi
49-
5029
protected=$(gh api "repos/$GITHUB_REPOSITORY/branches?protected=true&per_page=100" \
5130
| jq -r '.[].name')
5231
@@ -63,12 +42,6 @@ jobs:
6342
return
6443
fi
6544
66-
if [ "$DRY_RUN" = "true" ]; then
67-
echo "Would delete ($reason): $branch"
68-
deleted=$((deleted + 1))
69-
return
70-
fi
71-
7245
gh api "repos/$GITHUB_REPOSITORY/git/refs/heads/$branch" \
7346
-X DELETE 2>/dev/null \
7447
&& { echo "Deleted ($reason): $branch"; deleted=$((deleted + 1)); } \
@@ -137,4 +110,4 @@ jobs:
137110
138111
rm -f "$candidates"
139112
140-
echo "--- Done: $deleted branch(es) ${DRY_RUN:+would be }deleted ---"
113+
echo "--- Done: $deleted branch(es) deleted ---"

0 commit comments

Comments
 (0)