mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-19 19:18:34 +00:00
83af7aa92e
- only `cache-seeder` writes caches, every other workflow restores. Saves were being rejected once the repo went over its cache budget, leaving main's caches stale and PR runs building cold - seed the pnpm store and uv caches next to the go ones, so PRs warm-start on them rather than installing from scratch - prune keeps a single generation per key, including across go versions, where a toolchain bump leaves the previous build cache unusable. Reclaims ~2.6 GB immediately - prune runs every 6h instead of daily and trims to 6 GB, since CodeQL writes ~200 MB per push to main from outside this repo's workflows - pull requests and release branches no longer write pnpm, uv and binfmt caches, whose ref-scoped copies are never read again --------- Signed-off-by: silverwind <me@silverwind.io>
49 lines
1.7 KiB
YAML
49 lines
1.7 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 */6 * * *" # every six hours at :37
|
|
workflow_dispatch:
|
|
workflow_call:
|
|
|
|
permissions: {}
|
|
|
|
concurrency:
|
|
group: cache-prune
|
|
|
|
jobs:
|
|
prune:
|
|
runs-on: ubuntu-latest
|
|
if: github.repository == 'go-gitea/gitea'
|
|
permissions:
|
|
actions: write # to delete caches
|
|
env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
GH_REPO: ${{ github.repository }}
|
|
steps:
|
|
# Keep the newest generation per key, restores never reach the older ones.
|
|
- name: delete superseded caches
|
|
run: |
|
|
gh cache list --limit 1000 --json id,key,ref,createdAt |
|
|
jq -r 'group_by([.ref, (.key | sub("(-go[0-9.]+)?-[0-9a-f]{40,64}(-[0-9]+-[0-9]+)?$"; ""))])[]
|
|
| sort_by(.createdAt)[:-1][] | "\(.id) \(.key)"' |
|
|
while read -r id key; do
|
|
echo "deleting $key"
|
|
gh cache delete "$id" || true
|
|
done
|
|
|
|
# Deletes least recently used first, the order GitHub itself evicts in.
|
|
- 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 6000000000 ] && read -r id bytes key; do
|
|
echo "deleting $key"
|
|
gh cache delete "$id" || true
|
|
size=$((size - bytes))
|
|
done <<< "$(jq -r '.[] | "\(.id) \(.sizeInBytes) \(.key)"' <<< "$caches")"
|