File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-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 Stale Branch Caches
4+ on :
5+ schedule :
6+ - cron : 0 0 * * *
7+ workflow_dispatch :
8+
9+ jobs :
10+ cleanup :
11+ runs-on : ubuntu-latest
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+ steps :
18+ - name : Cleanup
19+ run : |
20+ echo "Fetching list of cache keys"
21+ cacheKeysForPR=$(gh cache list --limit 100 --json id,ref --jq '.[] | select(.ref != "refs/heads/main") | .id')
22+
23+ ## Setting this to not fail the workflow while deleting cache keys.
24+ set +e
25+ for cacheKey in $cacheKeysForPR
26+ do
27+ gh cache delete $cacheKey
28+ echo "Deleting $cacheKey"
29+ done
30+ echo "Done"
31+ env :
32+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
33+ GH_REPO : ${{ github.repository }}
You can’t perform that action at this time.
0 commit comments