Skip to content

Commit 3afe146

Browse files
committed
gha - add a workflow to clean cache on github when PR is closed
This will prevent cache to grow up and keep a clean state without waiting for the automatic deletion after 7 days
1 parent 2943b16 commit 3afe146

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Cleanup github runner caches on closed pull requests
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
7+
jobs:
8+
cleanup:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
actions: write
12+
steps:
13+
- name: Cleanup
14+
run: |
15+
echo "Fetching list of cache keys"
16+
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
17+
18+
## Setting this to not fail the workflow while deleting cache keys.
19+
set +e
20+
echo "Deleting caches..."
21+
for cacheKey in $cacheKeysForPR
22+
do
23+
gh cache delete $cacheKey
24+
done
25+
echo "Done"
26+
env:
27+
GH_TOKEN: ${{ github.token }}
28+
GH_REPO: ${{ github.repository }}
29+
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge

0 commit comments

Comments
 (0)