57 lines
1.7 KiB
YAML
57 lines
1.7 KiB
YAML
name: Delete Caches
|
|
|
|
# yamllint disable-line rule:truthy
|
|
on:
|
|
pull_request:
|
|
types: [closed]
|
|
workflow_dispatch:
|
|
inputs:
|
|
pr-number:
|
|
description: "Closed PR number"
|
|
type: string
|
|
required: true
|
|
|
|
jobs:
|
|
delete:
|
|
name: "Delete unused caches (PR #${{ github.event.inputs.pr-number || github.event.number }})"
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
actions: write
|
|
steps:
|
|
- name: Delete caches
|
|
run: |
|
|
ref="refs/pull/${{ github.event.inputs.pr-number || github.event.number }}/merge"
|
|
|
|
page=1
|
|
per_page=100
|
|
del_count=0
|
|
|
|
while true; do
|
|
res=$(curl -fsS \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "Authorization: token ${{ github.token }}" \
|
|
"https://api.github.com/repos/${{ github.repository }}/actions/caches?per_page=$per_page&page=$page")
|
|
|
|
res_count=$(echo $res | jq '.actions_caches | length')
|
|
if [ $res_count -eq 0 ]; then break; fi
|
|
|
|
targets=$(echo $res | jq \
|
|
--arg ref "$ref" \
|
|
'.actions_caches[] | select(.ref == $ref) | del(.created_at, .size_in_bytes, .version)')
|
|
echo "$targets"
|
|
|
|
for id in $(echo $targets | jq '.id'); do
|
|
curl -sS \
|
|
-X DELETE \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "Authorization: token ${{ github.token }}" \
|
|
"https://api.github.com/repos/${{ github.repository }}/actions/caches/$id"
|
|
((del_count+=1))
|
|
done
|
|
|
|
if [ $res_count -lt $per_page ]; then break; fi
|
|
((page+=1))
|
|
done
|
|
|
|
echo "Delete $del_count caches."
|