StackOverflow: Clean Actions Cache #3
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: "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!" |