Skip to content

Clear Cache

Clear Cache #23

Workflow file for this run

name: Clear Cache
on:
schedule:
- cron: '0 18 * * 5' # Runs weekly on Friday at 6 PM UTC
# https://crontab.guru/
# * * * * *
# | | | | |
# | | | | +---- Day of the week (0 - 7) (Sunday is both 0 and 7)
# | | | +------ Month (1 - 12)
# | | +-------- Day of the month (1 - 31)
# | +---------- Hour (0 - 23)
# +------------ Minute (0 - 59)
jobs:
cleanup-cache:
name: Cleanup cache
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
steps:
- name: Checkout repository 🛎️
uses: actions/checkout@v4
with:
show-progress: false
# Reference: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
- name: Cleanup cache 🧹
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}