File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Cleanup caches after merge
2+ on :
3+ pull_request :
4+ types :
5+ - closed
6+ workflow_dispatch :
7+
8+ jobs :
9+ cleanup :
10+ runs-on : ubuntu-latest
11+
12+ permissions :
13+ # `actions:write` permission is required to delete caches
14+ # See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
15+ actions : write
16+ contents : read
17+
18+ steps :
19+ - name : Check out code
20+ uses : actions/checkout@v4
21+
22+ - name : Cleanup cache
23+ run : |
24+ gh extension install actions/gh-actions-cache
25+
26+ REPO=${{ github.repository }}
27+ BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge
28+
29+ echo "Fetching list of cache key"
30+ cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH --limit 100 --sort size | cut -f 1 )
31+
32+ ## Setting this to not fail the workflow while deleting cache keys.
33+ set +e
34+ echo "Deleting caches..."
35+ for cacheKey in $cacheKeysForPR
36+ do
37+ gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
38+ done
39+ echo "Done"
40+ env :
41+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
You can’t perform that action at this time.
0 commit comments