Clear Cache #23
This file contains 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: 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 }} |