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