Skip to content

Commit 2b6c65c

Browse files
authored
ci: cleaning caches (#16752)
1 parent 104290e commit 2b6c65c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
2+
name: cleanup caches by a branch
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
9+
pr-cleanup:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out code
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="refs/pull/${{ github.event.pull_request.number }}/merge"
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+
echo "Deleting caches..."
28+
for cacheKey in $cacheKeysForPR
29+
do
30+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
31+
done
32+
echo "Done"
33+
env:
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)