File tree Expand file tree Collapse file tree 1 file changed +36
-5
lines changed
Expand file tree Collapse file tree 1 file changed +36
-5
lines changed Original file line number Diff line number Diff line change 11name : Delete Caches
22
33on :
4- pull_request :
4+ pull_request_target :
55 types : [closed]
66 workflow_dispatch :
77 inputs :
1212
1313jobs :
1414 delete :
15- name : " Delete unused caches (PR #${{ github.event.inputs.pr-number || github.event.number }}) "
15+ name : Delete caches
1616 runs-on : ubuntu-latest
1717 permissions :
1818 actions : write
19+ env :
20+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
1921 steps :
20- -
uses :
snnaplab/[email protected] 21- with :
22- ref : refs/pull/${{ github.event.inputs.pr-number || github.event.number }}/merge
22+ - name : Delete caches
23+ run : |
24+ ref="refs/pull/${{ github.event.inputs.pr-number || github.event.number }}/merge"
25+ sort="last_accessed_at"
26+ del_count=0
27+
28+ res=$(gh api --paginate \
29+ -H "Accept: application/vnd.github+json" \
30+ /repos/${{ github.repository }}/actions/caches?sort=$sort)
31+
32+ res_count=$(echo "$res" | jq '.actions_caches | length')
33+ if [[ "$res_count" -eq 0 ]]; then break; fi
34+
35+ targets=$(echo "$res" | jq \
36+ --arg ref "$ref" \
37+ '.actions_caches[] | select(.ref == $ref)
38+ | del(.created_at, .size_in_bytes, .version)')
39+ targets_count=$(echo "$targets" | jq -s 'length')
40+ if [[ "$targets_count" -eq 0 ]]; then break; fi
41+ echo "Found $targets_count caches"
42+ echo "$targets"
43+
44+ for id in $(echo "$targets" | jq '.id'); do
45+ echo "Delete cache with id: $id ..."
46+ gh api \
47+ --method DELETE \
48+ -H "Accept: application/vnd.github+json" \
49+ /repos/${{ github.repository }}/actions/caches/$id
50+ (( del_count += 1 ))
51+ done
52+
53+ echo "Deleted $del_count caches"
You can’t perform that action at this time.
0 commit comments