Skip to content

cleanup_caches

cleanup_caches #144

name: Cleanup caches
on:
workflow_dispatch:
repository_dispatch:
types: [cleanup_caches]
jobs:
cleanup:
name: 'Cleanup caches'
runs-on: ubuntu-latest
steps:
- name: Step 1 - Check out code
uses: actions/checkout@v4
- name: Step 2 - Cleanup
run: |
echo '> Install gh-actions-cache'
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH=$GITHUB_REF_NAME
echo '> Vars...'
echo "REPO: $REPO"
echo "BRANCH: $BRANCH"
echo '> Fetching list of cache key'
cacheKeysForPR=$(gh actions-cache list -R $REPO | 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 --confirm
done
echo 'Done'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}