File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ # https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
2+
3+ name : (Shared) Cleanup Branch Caches
4+ on :
5+ pull_request :
6+ types :
7+ - closed
8+ workflow_dispatch :
9+
10+ jobs :
11+ cleanup :
12+ runs-on : ubuntu-latest
13+ permissions :
14+ # `actions:write` permission is required to delete caches
15+ # 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
16+ actions : write
17+ contents : read
18+ steps :
19+ - name : Cleanup
20+ run : |
21+ echo "Fetching list of cache key"
22+ cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
23+
24+ ## Setting this to not fail the workflow while deleting cache keys.
25+ set +e
26+ echo "Deleting caches..."
27+ for cacheKey in $cacheKeysForPR
28+ do
29+ gh cache delete $cacheKey
30+ done
31+ echo "Done"
32+ env :
33+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
34+ GH_REPO : ${{ github.repository }}
35+ BRANCH : refs/pull/${{ github.event.pull_request.number }}/merge
You can’t perform that action at this time.
0 commit comments