-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
79 lines (73 loc) · 2.54 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
name: 'Wipe Github Actions cache'
description: 'Wipes all Github Actions caches for a repository.'
branding:
icon: 'archive'
color: 'orange'
inputs:
github-token:
description: 'Your GITHUB_TOKEN.'
required: false
default: ${{ github.token }}
dry-run:
description: 'List caches only, do not clear them.'
required: false
default: 'false'
page-size:
description: 'Page size for cache listing.'
required: false
default: '100'
runs:
using: "composite"
steps:
- name: List caches
id: list-caches
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
PAGE_SIZE: ${{ inputs.page-size }}
run: |
function list_caches {
local pageindex="$1"
gh api \
-H 'Accept: application/vnd.github+json' \
"/repos/${GITHUB_REPOSITORY}/actions/caches?per_page=${PAGE_SIZE}&page=${pageindex}"
}
pageindex=1
echo "fetching page ${pageindex}..."
first="$(list_caches "${pageindex}")"
total_count="$(jq -r '.total_count' <<< "${first}")"
all_ids="$(jq '.actions_caches[].id' <<< "${first}" | tr '\n' ' ')"
remaining="$((total_count-PAGE_SIZE))"
echo " cache ids in page ${pageindex}: ${all_ids}, ${remaining} remaining."
while [[ $remaining > 0 ]]; do
pageindex="$((pageindex+1))"
echo "fetching page ${pageindex}..."
ids="$(list_caches "${pageindex}" | jq '.actions_caches[].id' | tr '\n' ' ')"
all_ids="${all_ids} ${ids}"
remaining="$((remaining-PAGE_SIZE))"
if [[ $remaining < 0 ]]; then remaining=0; fi
echo " cache ids in page ${pageindex}: ${ids}, ${remaining} remaining."
done
echo "cache ids total: ${all_ids}"
echo "cache_ids=$all_ids" >> "$GITHUB_OUTPUT"
- name: Wipe caches
id: wipe
shell: bash
env:
GH_TOKEN: ${{ inputs.github-token }}
run: |
for id in ${{ steps.list-caches.outputs.cache_ids }}; do
if [[ "${{ inputs.dry-run }}" == 'true' ]]; then
echo "would delete cache $id using following command:"
echo gh api \
--method DELETE \
-H 'Accept: application/vnd.github+json' \
"/repos/${GITHUB_REPOSITORY}/actions/caches/$id"
else
echo "deleting cache $id"
gh api \
--method DELETE \
-H 'Accept: application/vnd.github+json' \
"/repos/${GITHUB_REPOSITORY}/actions/caches/$id"
fi
done