Skip to content

Commit

Permalink
chore(ci): add cache cleanup job for closed PRs (#3056)
Browse files Browse the repository at this point in the history
As per the GitHub docs, keep the Actions Cache clean and tidy by
explicitly purging any entries that reference the branch on close/merge
of a PR

Signed-off-by: Dominic Evans <[email protected]>
  • Loading branch information
dnwe authored Jan 7, 2025
1 parent 85a9c9f commit 1030b61
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/cache-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: Cleanup caches on PR close/merge
on:
pull_request:
types:
- closed

permissions:
actions: write # for cache management

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Delete Caches
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
run: |
gh cache list --ref "$BRANCH" --limit 100
CACHE_KEYS="$(gh cache list --ref "$BRANCH" --limit 100 --json id --jq '.[].id')"
for KEY in ${CACHE_KEYS}; do
echo "Deleting cache $KEY for ref $BRANCH"
gh cache delete "$KEY" || true
echo
done

0 comments on commit 1030b61

Please sign in to comment.