File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Cleanup caches by a branch
2+
3+ on :
4+ pull_request :
5+ types :
6+ - closed
7+ pull_request_target :
8+ types :
9+ - closed
10+ paths :
11+ - " **/*"
12+ - " !.github/**" # Important: Exclude PRs related to .github from auto-run
13+ - " !.github/workflows/**" # Important: Exclude PRs related to .github/workflows from auto-run
14+ - " !.github/actions/**" # Important: Exclude PRs related to .github/actions from auto-run
15+
16+ permissions :
17+ contents : read
18+ packages : read
19+
20+ jobs :
21+ check_paths :
22+ uses : ./.github/workflows/check_paths.yml
23+
24+ cleanup :
25+ name : Delete caches when PR is closed
26+ needs : check_paths
27+ if : needs.check_paths.outputs.githubfolder != 'true'
28+ runs-on : ubuntu-24.04
29+
30+ steps :
31+ - name : Cleanup
32+ run : |
33+ gh extension install actions/gh-actions-cache@d88f49218fd18a37f6f63ee4f8716764316a7f7d #v1.0.4
34+
35+ echo "Fetching list of cache key"
36+ cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )
37+
38+ ## Setting this to not fail the workflow while deleting cache keys.
39+ set +e
40+ echo "Deleting caches..."
41+ for cacheKey in $cacheKeysForPR
42+ do
43+ gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
44+ done
45+ echo "Done"
46+ env :
47+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
48+ REPO : ${{ github.repository }}
49+ BRANCH : refs/pull/${{ github.event.pull_request.number }}/merge
You can’t perform that action at this time.
0 commit comments