Skip to content

Cleanup cache

Cleanup cache #10284

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@v6
- name: Cleanup cache
run: |
gh extension install actions/gh-actions-cache
REPO="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
PR="${PR_NUMBER}"
BRANCH="${EVENT_REF}"
REF="${CACHE_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 }}
GITHUB_SERVER_URL: ${{ github.server_url }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
EVENT_REF: ${{ github.event.ref }}
CACHE_REF: ${{ inputs.branch || (github.event.pull_request.number && 'refs/pull/${{ github.event.pull_request.number }}/merge') || github.event.ref }}