Skip to content

Commit c7ac6dd

Browse files
authored
ci: add release-clean-up workflow
1 parent ae616cb commit c7ac6dd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

.github/workflows/release-clean-up

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Cleanup Old Releases
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 2 * *'
7+
8+
jobs:
9+
cleanup:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Install GitHub CLI
17+
uses: cli/cli-action@v2
18+
19+
- name: Delete old releases (keep latest 20)
20+
env:
21+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
run: |
23+
gh api repos/${{ github.repository }}/releases --paginate \
24+
| jq -r 'sort_by(.created_at) | reverse | .[20:] | .[] | @base64' \
25+
| while read release; do
26+
_jq() { echo ${release} | base64 --decode | jq -r ${1}; }
27+
id=$(_jq '.id')
28+
tag=$(_jq '.tag_name')
29+
echo "Deleting release ID: $id, tag: $tag"
30+
gh api -X DELETE repos/${{ github.repository }}/releases/$id
31+
gh api -X DELETE repos/${{ github.repository }}/git/refs/tags/$tag
32+
done

0 commit comments

Comments
 (0)