Skip to content

Commit 5eaba20

Browse files
authored
chore(workflow): cleanup cached on pull request close (#173)
1 parent 2a17378 commit 5eaba20

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: cleanup caches on pull request close
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
cleanup:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Cleanup
16+
run: |
17+
gh extension install actions/gh-actions-cache
18+
19+
REPO=${{ github.repository }}
20+
BRANCH=${{ github.ref }}
21+
22+
echo "Fetching list of cache key"
23+
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
24+
25+
## Setting this to not fail the workflow while deleting cache keys.
26+
set +e
27+
28+
echo "Deleting caches..."
29+
for cacheKey in $cacheKeysForPR
30+
do
31+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
32+
done
33+
34+
echo "Done"
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)