sbt-typelevel icon indicating copy to clipboard operation
sbt-typelevel copied to clipboard

Smarter caching in CI

Open armanbilge opened this issue 3 years ago • 4 comments

~~Two~~ Three things to consider:

  • cache all deps, not just sbt deps
  • be robust to different ci jobs that may download different deps (e.g., jvm vs js vs scalafix vs site)
  • don't get invalidated by simple changes tobuild.sbt etc.

armanbilge avatar May 02 '22 23:05 armanbilge

One idea to fix might be to determine the cache key not just from the build configuration, but also from the matrix. Effectively each job in the matrix would get its own cache.

GH actions supports caches of up to 10 GB before it starts evicting old caches. If each job gets its own cache this could add up real quick, at which point it would be useless.

armanbilge avatar May 02 '22 23:05 armanbilge

GH actions supports caches of up to 10 GB before it starts evicting old caches. If each job gets its own cache this could add up real quick, at which point it would be useless.

Perhaps this could be mitigated by using restore keys, provided the keys were prefixed in a way that allowed the cache to be layered nicely

DavidGregory084 avatar May 03 '22 09:05 DavidGregory084

That's a good point. I'd say if we can get sbt and plugins out of the cache then it's a win. Library deps are icing on the cake :)

armanbilge avatar May 03 '22 10:05 armanbilge

Seems we may be caching some files we are not supposed to, like *.lock and ivydata-*.properties. This should be fixed as well. https://www.scala-sbt.org/1.x/docs/GitHub-Actions-with-sbt.html#Caching

armanbilge avatar Jun 14 '22 02:06 armanbilge

The setup-java action now supports caching. I think we should just use that and call it a day.

  • https://github.com/typelevel/sbt-typelevel/pull/300

armanbilge avatar Oct 08 '22 21:10 armanbilge

See also some discussion about why the "smarter caching" proposal that was originally the goal of this issue, actually would not work. tl;dr if you use the restore key to fallback to a non-exact-match cache, then when you create a new cache it will also include unnecessary stuff from the fallback cache. This causes your cache to grow unboundedly.

  • https://github.com/actions/setup-java/issues/269
  • https://github.com/actions/cache/issues/788

armanbilge avatar Oct 21 '22 01:10 armanbilge