julia-actions / cache

A shortcut action to cache Julia artifacts, packages, and registries.
MIT License
38 stars 9 forks source link

Fix issues with custom cache eviction #135

Closed omus closed 5 months ago

omus commented 5 months ago

Fixes https://github.com/julia-actions/cache/issues/113

In https://github.com/julia-actions/cache/pull/71 when we introduced saving cache entries for each matrix job we also introduced a manual cache eviction step to attempt to evict unnecessary cache entries in a better way than the default GitHub behavior (evict the oldest). Unfortunately, we have ended up being a little overly aggressive in our cache eviction policy which has resulted in the following problems:

  1. We assume that a cache entry will be saved upon every job run so it is safe to evict all cache entries on that branch before we save the new entry. For failed jobs no new cache entry is saved so we end up starting from scratch on subsequent runs. In this PR I've updated the behavior to always keep the latest cache entry (possibly in addition to the new cache entry) so failures like this can use the last saved entry.
  2. We perform cache eviction on entries from the default branch. As GitHub action caches can only be pulled from the current branch or the base branch the default branch can be rather important for falling back on for a base cache entry. When new commits are added to the default branch the old cache entries are evicted which can leave PRs with no base cache to fall back on. I now avoid performing manual cache eviction on the default branch to avoid this kind of problem.
omus commented 5 months ago

I've done some testing against this change on a private repo and have been happy with the results. We still have the issue with the scenario where if a job which fails it doesn't save a cache entry. At least reliably fallback on the default branch cache entry so things are in a much better state.

IanButterworth commented 5 months ago

Sounds good and thanks for the external testing