Update delete-old-releases.yml

This commit is contained in:
XargonWan 2024-01-02 13:39:13 +01:00 committed by GitHub
parent c7a0b72f63
commit a7c69c4e60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,11 +24,12 @@ jobs:
THRESHOLD_DATE=$(date -d "1 month ago" +%Y-%m-%dT%H:%M:%SZ)
# Get releases older than 1 month
OLD_RELEASES=$(jq --arg threshold "$THRESHOLD_DATE" '. | select(.published_at < $threshold) | .id' <<< "$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/$GITHUB_REPOSITORY/releases)")
OLD_RELEASES=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases" | jq --arg threshold "$THRESHOLD_DATE" '.[] | select(.published_at < $threshold) | .id')
# Delete old releases
for release_id in $OLD_RELEASES; do
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id"
curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id"
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}