Skip to content

Commit 2e8753a

Browse files
committed
add github runner cache gc
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
1 parent 9d97fe7 commit 2e8753a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.github/workflows/gc-cache.yaml

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

0 commit comments

Comments
 (0)