mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Cache improvements [ci] (#80898)
* Cleanup old pip caches * Add workflow to delete caches for closed PRs
This commit is contained in:
parent
4b89d087bb
commit
ba8f69a5ce
56
.github/workflows/cache.yml
vendored
Normal file
56
.github/workflows/cache.yml
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
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 -fsS \
|
||||||
|
-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."
|
64
.github/workflows/ci.yaml
vendored
64
.github/workflows/ci.yaml
vendored
@ -551,6 +551,70 @@ jobs:
|
|||||||
pip install --cache-dir=$PIP_CACHE -r requirements_test.txt --use-deprecated=legacy-resolver
|
pip install --cache-dir=$PIP_CACHE -r requirements_test.txt --use-deprecated=legacy-resolver
|
||||||
pip install -e .
|
pip install -e .
|
||||||
|
|
||||||
|
cleanup-cache:
|
||||||
|
name: Cleanup old pip caches
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
needs:
|
||||||
|
- base
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
steps:
|
||||||
|
- name: Cleanup
|
||||||
|
run: |
|
||||||
|
sort="last_accessed_at"
|
||||||
|
page=1
|
||||||
|
per_page=100
|
||||||
|
del_count=0
|
||||||
|
index=0
|
||||||
|
|
||||||
|
all_versions=($(echo $ALL_PYTHON_VERSIONS | tr -d \',[]))
|
||||||
|
|
||||||
|
if [[ "${{ github.ref }}" == "refs/heads/dev" ]] \
|
||||||
|
|| [[ "${{ contains(github.event.pull_request.labels.*.name, 'ci-keep-cache') }}" == "true" ]]
|
||||||
|
then
|
||||||
|
index=1
|
||||||
|
echo "Keep one entry per Python version"
|
||||||
|
fi
|
||||||
|
|
||||||
|
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?sort=$sort&per_page=$per_page&page=$page")
|
||||||
|
|
||||||
|
res_count=$(echo $res | jq '.actions_caches | length')
|
||||||
|
if [ $res_count -eq 0 ]; then break; fi
|
||||||
|
|
||||||
|
echo "Check ref: ${{ github.ref }}"
|
||||||
|
for version in ${all_versions[@]}; do
|
||||||
|
key="${{ runner.os }}-$version.+-pip"
|
||||||
|
echo "Check key regex: $key"
|
||||||
|
|
||||||
|
# Select all cache keys which match the ref and key regex
|
||||||
|
# Keep the first entry for 'ref/heads/dev'
|
||||||
|
targets=$(echo $res | jq \
|
||||||
|
--arg ref "${{ github.ref }}" --arg key "$key" --arg index $index \
|
||||||
|
'[.actions_caches[] | select(.ref == $ref) | select(.key | test($key))][$index | fromjson:][] | del(.created_at, .size_in_bytes, .version)')
|
||||||
|
|
||||||
|
if [ $(echo $targets | jq -s 'length') -eq 0 ]; then continue; fi
|
||||||
|
echo "$targets"
|
||||||
|
|
||||||
|
for id in $(echo $targets | jq '.id'); do
|
||||||
|
curl -fsS \
|
||||||
|
-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
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $res_count -lt $per_page ]; then break; fi
|
||||||
|
((page += 1))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Deleted $del_count caches."
|
||||||
|
|
||||||
hassfest:
|
hassfest:
|
||||||
name: Check hassfest
|
name: Check hassfest
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
|
Loading…
x
Reference in New Issue
Block a user