Skip to content

Add skip-cache-restore option - #171

Open
lurtz wants to merge 2 commits into
bazel-contrib:mainfrom
lurtz:skip-cache-restore
Open

lurtz wants to merge 2 commits into
bazel-contrib:mainfrom
lurtz:skip-cache-restore

Conversation

@lurtz

@lurtz lurtz commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

This is useful for rebuilding caches. The current cache restore fallback logic leads to saving only one Github cache for each cache type and never updating it. Over time caches and code start to drift, which requires refreshing caches. With skip-cache-restore they can be refreshed if needed.

Because the repository cache can also change by e.g. changes in .bazelversion, add the lockfile to avoid hash collisions. Otherwise writing a new cache might fail, even if its content differs.

lurtz added 2 commits July 1, 2026 11:44
This is useful for rebuilding caches. The current cache restore fallback logic leads to saving only one Github cache for each cache type and never updating it. Over time caches and code start to drift, which requires refreshing caches. With `skip-cache-restore` they can be refreshed if needed.
The content of the repository cache can be influenced by more than MODULE.bazel or the WORKSPACE files. E.g. .bazelversion or files included by MODULE.bazel can either define the version of dependencies or pull in more. As these will eventually land in the lockfile add it to the hash to have different hash values on changes of pulled in dependencies.
@lurtz
lurtz marked this pull request as ready for review July 1, 2026 11:56
@lurtz

lurtz commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

FYI I wondered if it makes sense to treat the repository and disk cache individually, but decided against that. If you think this is useful I can change the code.

@p0deje

p0deje commented Jul 25, 2026

Copy link
Copy Markdown
Member

Sorry, I missed this PR! Whenever I need to bust the cache, I normally would bump the cache-version input, so it generates new caches and pushes them, while older caches would be garbage-collected by GitHub Actions eventually. Is this workflow sufficient for your use-case?

@lurtz

lurtz commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Never mind. To keep the behavior I currently have with skip-cache-restore, I need to increase cache-version each time MODULE.bazel.lock changes. And for that I would need to get the latest cache-version from somewhere.

My first attempt would be to use gh cache list, extract the the version from the setup-bazel-* caches and use the highest value + 1. Let my know if you have a better idea.

I can try if that works, but I cannot promise that I will come back quickly, because I currently have a working solution with the code of this PR and there is at the moment no pressure to change it.

@AlexanderLanin

Copy link
Copy Markdown

Is this workflow sufficient for your use-case?

Not quite, since github cache beyond 10GB costs money we are working on solutions how to evict caches as soon as possible. And since we run this on 100+ repos we dont want to do anything manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants