Cleanup cache #1927
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: Cleanup cache | |
on: | |
delete: | |
pull_request: | |
types: | |
- closed | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: 'Branch ref to delete caches for' | |
required: true | |
type: string | |
jobs: | |
cleanup: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Cleanup cache | |
run: | | |
gh extension install actions/gh-actions-cache | |
REPO=${{ github.server_url }}/${{ github.repository }} | |
PR=${{ github.event.pull_request.number }} | |
BRANCH=${{ github.event.ref }} | |
REF=${{ inputs.branch || (github.event.pull_request.number && 'refs/pull/$PR/merge') || github.event.ref }} | |
echo "Fetching list of cache key" | |
echo $PR | |
echo $BRANCH | |
echo $REF | |
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $REF | cut -f 1 ) | |
echo $cacheKeysForPR | |
## 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 $REF --confirm | |
done | |
echo "Done" | |
env: | |
GH_TOKEN: ${{ github.token }} |