Files
egui/.github/workflows/cache_cleanup.yml
T
Emil ErnerfeldtandClaude Opus 5 f161959d59 CI: run once per PR, and stop PR caches from evicting the main cache (#8507)
The `Run tests` job takes 9-12 minutes because it finds no cargo cache
and rebuilds all 390 crates; the last run that hit the cache took 4m20s
for the whole job. The repository holds 30 caches totalling 10.6 GB,
over the 10 GB limit, so entries are evicted constantly. Each PR saves
its own ~2.5 GB copy of every job cache, which pushes out the `main`
cache that every new PR starts from.

* `on: [push, pull_request]` ran the whole workflow twice for a PR from
a branch in this repo, doubling both runner time and cache writes. The
push half now only runs for `main`.
* Only `main` writes to the cargo cache (`save-if`). PRs still read it.
* New workflow deletes the caches of a PR when it is closed.

* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-07 09:51:25 +02:00

34 lines
1.0 KiB
YAML

# Delete the GitHub Actions caches of a pull request once it is closed.
#
# A repository can only hold 10 GB of caches, and the oldest ones are evicted when it is full.
# Without this the caches of merged pull requests would push out the `main` cache
# that every new pull request starts from.
name: Cache Cleanup
on:
pull_request:
types: [closed]
permissions:
actions: write
jobs:
cleanup:
name: Delete the caches of the closed PR
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Delete caches
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR_REF: refs/pull/${{ github.event.pull_request.number }}/merge
BRANCH_REF: refs/heads/${{ github.event.pull_request.head.ref }}
run: |
for ref in "$PR_REF" "$BRANCH_REF"; do
echo "Deleting the caches of $ref"
gh cache list --ref "$ref" --limit 100 --json id --jq '.[].id' \
| xargs -r -I {} gh cache delete {}
done