Always save new cache for incremental builds

Is there a way to tell the Actions cache to always cache at the end of the run, even if the key cache hit was successful? I am using Bazel, which provides incremental builds. Thus, by saving the whole bazel cache after each CI run, I can save a lot of time and only run what has changed, according the bazel.

I don’t want to use the git sha or anything in the cache key because that would mean the cache is evicted every time a new commit is pushed, which defeats the purpose of incremental builds with Bazel.

I know the caches resave if the cache-hit value is false. Is there a way to manually set this cache-hit value to false perhaps? Or is there another way to always update the cache after a CI build?

:wave: @TerrenceHo, this is not fully supported by the default cache action.

There’s a discussion on this topic and some workarounds in Enable always writing cache to support hermetic build systems · Issue #109 · actions/cache · GitHub.

I don’t want to use the git sha or anything in the cache key because that would mean the cache is evicted every time a new commit is pushed

The cache won’t be evicted until you reach usage limits, and you can still pull from an old cache using restore-keys.

A user suggested a similar solution in Enable always writing cache to support hermetic build systems · Issue #109 · actions/cache · GitHub

For more on using restore-keys and how our eviction process works, see Caching dependencies to speed up workflows - GitHub Docs