mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-04 08:27:31 +00:00
b87fdd5da4
Fix minor issue: `cache-prune` logs `jq: error: writing output failed: Broken pipe` when it has nothing to delete, because the loop stops reading as soon as it is under the limit while `jq` still has output pending. Reading from a here-string removes the pipe. --------- Signed-off-by: silverwind <me@silverwind.io>
38 lines
1.2 KiB
YAML
38 lines
1.2 KiB
YAML
name: cache-prune
|
|
|
|
# Keeps the repository's total cache size below a fixed limit, so that GitHub never
|
|
# rejects a save for being over the allowance.
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "37 2 * * *" # every day at 02:37 UTC
|
|
workflow_dispatch:
|
|
workflow_call:
|
|
|
|
permissions:
|
|
actions: write # to delete caches
|
|
|
|
concurrency:
|
|
group: cache-prune
|
|
|
|
jobs:
|
|
prune:
|
|
runs-on: ubuntu-latest
|
|
if: github.repository == 'go-gitea/gitea'
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
GH_REPO: ${{ github.repository }}
|
|
steps:
|
|
# Deletes least recently used first, the order GitHub itself evicts in, which takes
|
|
# superseded generations first as those stop being restored once a newer one exists.
|
|
- name: delete caches over the size limit
|
|
run: |
|
|
caches=$(gh cache list --limit 1000 --sort last_accessed_at --order asc --json id,key,sizeInBytes)
|
|
size=$(jq '[.[].sizeInBytes] | add // 0' <<< "$caches")
|
|
echo "cache usage: $((size / 1000000)) MB"
|
|
while [ "$size" -gt 6500000000 ] && read -r id bytes key; do
|
|
echo "deleting $key"
|
|
gh cache delete "$id"
|
|
size=$((size - bytes))
|
|
done <<< "$(jq -r '.[] | "\(.id) \(.sizeInBytes) \(.key)"' <<< "$caches")"
|