File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 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 }}
You can’t perform that action at this time.
0 commit comments