Cleanup Old Releases #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Cleanup Old Releases | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 0 2 * *' | |
| jobs: | |
| cleanup: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install GitHub CLI | |
| run: sudo apt-get install -y gh | |
| - name: Delete old releases (keep latest 12) | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api repos/${{ github.repository }}/releases --paginate \ | |
| | jq -r 'sort_by(.created_at) | reverse | .[12:] | .[] | @base64' \ | |
| | while read -r release; do | |
| _jq() { | |
| echo "$release" | base64 --decode | jq -r "$1" | |
| } | |
| id=$(_jq '.id') | |
| tag=$(_jq '.tag_name') | |
| echo "Deleting release ID: $id, tag: $tag" | |
| gh api -X DELETE repos/${{ github.repository }}/releases/$id | |
| gh api -X DELETE repos/${{ github.repository }}/git/refs/tags/$tag | |
| done |