File tree Expand file tree Collapse file tree 1 file changed +26
-6
lines changed Expand file tree Collapse file tree 1 file changed +26
-6
lines changed Original file line number Diff line number Diff line change 11name : Cleanup Old Releases
22
33on :
4- workflow_dispatch :
54 release :
6- types : [published ]
5+ types : [created ]
76
87jobs :
98 cleanup :
109 runs-on : ubuntu-latest
1110 steps :
11+ - name : Set up GitHub CLI
12+ run : |
13+ type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
14+ curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
15+ && sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
16+ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
17+ && sudo apt update \
18+ && sudo apt install gh -y
19+
1220 - name : Delete old releases
13- uses :
dev-drprasad/[email protected] 14- with :
15- keep_latest : 1
16- delete_tags : true
1721 env :
1822 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
23+ run : |
24+ # Keep no releases (excluding current new release)
25+ releases=$(gh release list --limit 100 --exclude-drafts --exclude-prereleases --json tagName,createdAt -q '.[].tagName')
26+ keep=0
27+ count=0
28+
29+ echo "Current releases (oldest first):"
30+ echo "$releases"
31+
32+ for release in $releases; do
33+ ((count++))
34+ if ((count > keep)); then
35+ echo "Deleting old release: $release"
36+ gh release delete "$release" --yes
37+ fi
38+ done
You can’t perform that action at this time.
0 commit comments