Skip to content

Commit fd96ba4

Browse files
committed
CI: Add workflow to cleanup PR caches when closed
This is pretty much copied from the GitHub Actions documentation: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
1 parent 701505e commit fd96ba4

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
2+
name: 🧹 Cache Cleanup
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
cleanup:
10+
name: Cleanup PR caches
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Cleanup
14+
env:
15+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
GH_REPO: ${{ github.repository }}
17+
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
18+
run: |
19+
echo "Fetching list of cache key"
20+
cache_keys_for_pr=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
21+
# Setting this to not fail the workflow while deleting cache keys.
22+
set +e
23+
echo "Deleting caches..."
24+
for cache_key in $cache_keys_for_pr; do
25+
gh cache delete $cache_key
26+
echo "Deleted: $cache_key"
27+
done
28+
echo "Done"

0 commit comments

Comments
 (0)