Delete Old Releases #444
This file contains 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: Delete Old Releases | |
on: | |
schedule: | |
- cron: '0 5 * * *' | |
workflow_dispatch: | |
jobs: | |
delete-releases: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Delete all releases except the latest two | |
run: | | |
releases=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s "https://api.github.com/repos/$GITHUB_REPOSITORY/releases") | |
latest_id1=$(echo "$releases" | jq '.[0].id') | |
latest_id2=$(echo "$releases" | jq '.[1].id') | |
ids_to_delete=$(echo "$releases" | jq ".[] | select(.id != $latest_id1 and .id != $latest_id2) | .id") | |
for id in $ids_to_delete; do | |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$id" | |
done | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |