Skip to content

Cleanup Caches

Cleanup Caches #43

Workflow file for this run

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