Skip to content

StackOverflow: Clean Actions Cache #3

StackOverflow: Clean Actions Cache

StackOverflow: Clean Actions Cache #3

name: "StackOverflow: Clean Actions Cache"
on:
workflow_dispatch:
schedule:
- cron: "30 0 * * *"
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Cleanup
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
run: |
gh extension install actions/gh-actions-cache
echo "Fetching list of cache keys..."
cacheKeys=$(gh actions-cache list -R $REPO | cut -f 1)
cacheKeys=$(echo "$cacheKeys" | sed '1d')
## needed to not fail workflow while deleting keys
set +e
echo "Deleting old cache keys..."
for cacheKey in $cacheKeys; do
echo "Deleting $cacheKey..."
gh actions-cache delete $cacheKey -R $REPO --confirm
done
echo "Done!"