Cleanup Caches #43
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 Caches | |
| on: | |
| schedule: | |
| - cron: "0 2 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| actions: write | |
| jobs: | |
| cleanup: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Delete caches older than 5 days | |
| run: | | |
| CUTOFF=$(date -d '5 days ago' +%s) | |
| CACHES=$(curl -s \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/caches?per_page=100" \ | |
| | jq -r '.actions_caches[]') | |
| echo "$CACHES" | jq -r '. | select(.key | startswith("dotnet-") or startswith("node-")) | select(.created_at) | "\(.id) \(.created_at) \(.key)"' | \ | |
| while read -r ID CREATED_AT KEY; do | |
| CACHE_DATE=$(date -d "$CREATED_AT" +%s) | |
| if [ "$CACHE_DATE" -lt "$CUTOFF" ]; then | |
| echo "🗑️ Deleting cache: $KEY (created: $CREATED_AT)" | |
| curl -s -X DELETE \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/actions/caches/$ID" | |
| else | |
| echo "✅ Keeping cache: $KEY (created: $CREATED_AT)" | |
| fi | |
| done |