Skip to content

Cleanup cache

Cleanup cache #604

Workflow file for this run

name: Cleanup cache
on:
push:
paths:
- 'yarn.lock'
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: $PR"
echo "Branch: $BRANCH"
echo "Ref: $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 }}