File tree 2 files changed +59
-0
lines changed
2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Cleanup caches
2
+
3
+ on :
4
+ workflow_run :
5
+ workflows : [build]
6
+ types : [completed]
7
+
8
+ jobs :
9
+ cache :
10
+ runs-on : ubuntu-latest
11
+ steps :
12
+ - run : |
13
+ caches=$(gh cache list -R ${{ github.repository }} -L 100 --json id,key,ref -S last_accessed_at -O desc)
14
+ echo "$caches" | jq -c '
15
+ map(select(.key | startswith("x86_64-w64-mingw32-") or
16
+ startswith("i686-w64-mingw32-") or
17
+ startswith("x86_64-windows-msvc-"))) |
18
+ group_by(.ref) |
19
+ map({
20
+ ref: .[0].ref,
21
+ caches: map(.key)
22
+ }) |
23
+ .[]
24
+ ' |
25
+ while read -r group; do
26
+ pr=$(echo "$group" | jq -r '.ref | capture("refs/pull/(?<num>[0-9]+)/merge").num')
27
+ if [[ -n "$pr" ]] && [ "$(gh pr view -R ${{ github.repository }} $pr --json state --jq '.state')" == "OPEN" ]; then
28
+ keys=$(echo "$group" | jq -c '.caches[1:]')
29
+ else
30
+ keys=$(echo "$group" | jq -c '.caches')
31
+ fi
32
+ echo "$keys" | jq -r '.[]' | while read -r key; do
33
+ gh cache delete "$key" -R ${{ github.repository }}
34
+ done
35
+ done
36
+ env :
37
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
1
+ name : Cleanup caches PR
2
+
3
+ on :
4
+ pull_request_target :
5
+ types : closed
6
+
7
+ jobs :
8
+ pr_cache :
9
+ runs-on : ubuntu-latest
10
+ steps :
11
+ - run : |
12
+ gh extension install actions/gh-actions-cache
13
+ set +e
14
+ keys=$(gh actions-cache list -R ${{ github.repository }} -B $BRANCH | cut -f 1)
15
+ set +e
16
+ for key in $keys
17
+ do
18
+ gh actions-cache delete $key -R ${{ github.repository }} -B $BRANCH --confirm
19
+ done
20
+ env :
21
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22
+ BRANCH : refs/pull/${{ github.event.pull_request.number }}/merge
You can’t perform that action at this time.
0 commit comments