-
Notifications
You must be signed in to change notification settings - Fork 7
29 lines (27 loc) · 1.09 KB
/
clear-caches.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
name: clear-caches
on: workflow_dispatch
jobs:
clear:
name: Clear all caches
runs-on: ubuntu-latest
steps:
- run: |
# Keep track of the total number of caches deleted
TOTAL_COUNT=0
# The cache list is paginated, so we won't necessarily get all ids with the first call
while true; do
LIST_CACHES=$(gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/actions/caches)
REMAINING_COUNT=$(echo $LIST_CACHES | jq .total_count)
# If there are no more, we're done!
[[ $REMAINING_COUNT > 0 ]] || break
# Parse out the list of ids
IDS=$(echo $LIST_CACHES | jq .actions_caches[].id)
for ID in ${IDS[@]}; do
echo "Clearing $ID"
gh api --method DELETE -H "Accept: application/vnd.github+json" /repos/${{ github.repository }}/actions/caches/$ID
TOTAL_COUNT=$((TOTAL_COUNT + 1))
done
done
echo "Cleared $TOTAL_COUNT caches"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}