[Question] What to cache for CI using the node_modules linker? #2621
-
It is common in CI to cache folders across multiple stages. So far, I see two options: 1. Caching
|
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 23 replies
-
At work we check in the CI cache on the repo and use PnP, so no cache is really needed (apart the repo itself). We still run an install to hydrate the build artifacts, but I plan to find a way to get rid of that. |
Beta Was this translation helpful? Give feedback.
-
The approach to caching heavily depends on the project and the CI. Sometimes CI cache compression and decompression takes more time, than Yarn downloading artifacts from the registry, in this case caching |
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
-
When using node_modules, I agree with @larixer. Just Besides that, I really like to take benefit of Some reasons
More real-world action example I use: https://github.com/belgattitude/nextjs-monorepo-example/blob/main/.github/actions/yarn-nm-install/action.yml. There' probably more small enhancements to be made. But for now I'm fine. When possible "pnp" will probably give better results, but I've been often blocked. |
Beta Was this translation helpful? Give feedback.
-
can you please explain how currently caching is done within the node? We are using node16, PNP (without committing artifacts, eg nonzeroconfig) and would like to reuse the cache on GitLab. unfortunately, there is no documentation for CI on the berry website, only on the classic one. |
Beta Was this translation helpful? Give feedback.
-
This is most painful for us in a monorepo where some projects use different versions of We're eyeballing a strategy where time-consuming-to-build dependencies are maintained in a separate tree that isn't restored when the root/primary tree is; in this way, "building binaries" only occurs in the actions that require these dependencies. |
Beta Was this translation helpful? Give feedback.
-
I've got an updated gist here: https://gist.github.com/belgattitude/042f9caf10d029badbde6cf9d43e400a TLDR;
I'll update the gist to allow blacklisting some bots (dependabot, renovate), generally they don't need to create a cache for node-modules/install-state. |
Beta Was this translation helpful? Give feedback.
The approach to caching heavily depends on the project and the CI. Sometimes CI cache compression and decompression takes more time, than Yarn downloading artifacts from the registry, in this case caching
.yarn/cache
not worth it. Caching allnode_modules
locations and.yarn/install-state.gz
should more often then not be beneficial, because any native tool typically creates a lot of files much faster thanNode.js
, plus you will avoid rebuilding your install-time dependencies. Also, make sure to usecompressionLevel: 0
in.yarnrc.yml
if you are on Yarn 2 or 3, (it is 0 by default on Yarn 4+) if you usenode-modules
linker all the time, this affects install times very much.