Skip to content

Clean Caches

Clean Caches #12

Workflow file for this run

name: Clean Caches
on:
push:
branches: [ "master", "beta" ]
paths:
- '**/package-lock.json'
- '**/yarn.lock'
pull_request:
paths:
- '**/package-lock.json'
- '**/yarn.lock'
workflow_dispatch:
schedule:
- cron: '0 0 1 * *'
# Run monthly, at 00:00 on the 1st day of month.
# run single job
concurrency:
group: clean-caches
cancel-in-progress: true
jobs:
build:
strategy:
fail-fast: true
runs-on: ubuntu-latest
name: Cache Cleaner
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.ACCESS_TOKEN }}
# https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
- name: Cleanup caches
shell: bash
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH=${{ github.ref }}
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.ACCESS_TOKEN }}