Skip to content

Commit 0b4a001

Browse files
committed
chore: cleanup cache for closed PRs
1 parent 00936e8 commit 0b4a001

File tree

1 file changed

+32
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)