Cooker/.github/workflows/delete-old-releases.yml

34 lines
1.1 KiB
YAML

name: Clean Old Releases
on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight
jobs:
clean-releases:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Git
run: |
git config user.email "${{ secrets.GIT_MAIL }}"
git config user.name "${{ secrets.GIT_USERNAME }}"
- name: Clean Old Releases
run: |
# Define the threshold date (1 month ago)
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)")
# 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"
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}