Skip to content

Commit 2fb8033

Browse files
committed
CI: clear gh actions cache for closed PR branches
1 parent 4dbe48e commit 2fb8033

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)