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

36 lines
1.1 KiB
YAML
Raw Normal View History

2024-01-02 12:37:10 +00:00
name: Clean Old Releases
2023-09-29 08:11:41 +00:00
on:
schedule:
2024-01-02 12:37:10 +00:00
- cron: '0 0 * * *' # Run daily at midnight
2024-01-02 12:37:54 +00:00
workflow_dispatch:
2023-09-29 08:11:41 +00:00
jobs:
2024-01-02 12:37:10 +00:00
clean-releases:
2023-09-29 08:11:41 +00:00
runs-on: ubuntu-latest
2024-01-02 12:37:10 +00:00
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)
2024-01-02 12:39:13 +00:00
2024-01-02 12:37:10 +00:00
# Get releases older than 1 month
2024-01-02 12:39:13 +00:00
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')
2024-01-02 12:37:10 +00:00
# Delete old releases
for release_id in $OLD_RELEASES; do
2024-01-02 12:39:13 +00:00
curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id"
2024-01-02 12:37:10 +00:00
done
2024-01-02 12:39:13 +00:00
2024-01-02 12:37:10 +00:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}