Cleanup pip cache workaround [ci] (#82272)

This commit is contained in:
Marc Mueller 2022-11-17 21:14:54 +01:00 committed by GitHub
parent a07117470e
commit e3749e0f76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 56 deletions

View File

@ -1,56 +0,0 @@
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."

View File

@ -558,6 +558,10 @@ jobs:
- base
permissions:
actions: write
# Limit to 'dev' branch until permissions issue is resolved
# https://github.com/home-assistant/core/pull/80898
# https://github.com/home-assistant/core/pull/82254
if: github.ref == 'refs/heads/dev'
steps:
- name: Cleanup
run: |