New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify caching of npm / Yarn / pnpm dependencies #304
Comments
Hey @borekb , caching means exactly the same what actions/cache does. We cache global package manager cache on machine (
It depends on number of dependencies in project. For small projects with 5-10 dependencies, cache doesn't bring much benefits (that fact that VMs can have a bit different connection speed, this random factor will neutralize caching profit. |
Thanks, that is great info, I was mostly unsure about what a "dependency" means here. Caching the cache makes sense 👍. Two possible suggestions for README:
... or maybe just point to the ADR that contains it all. Thanks again! |
Also got questions regarding caching (please let me know it if doesnt belong here and i'll open a separate ticket): Is it ok to use the same cache for different node versions?I notice you don't use node-version as part of the cache key: setup-node/src/cache-restore.ts Line 28 in aa759c6
I see 2 potential issues with this:
how can we tell if a cache hit occured?If the cache was hit, installation can be done in offline mode, eg for pnpm |
@borekb makes sense to me. Let me think how we can improve readme @dominikg , since we cache "global cache" instead "node_modules", Node.js version doesn't matter and cache is identical. The caching results of "post-install" scripts is not recommended because they can have side affects (change anything on machine outside of "node_modules" folder) or produce different results based on VM state (Image version on VM is updated every week and if result of some scripts depend on machine state, build can be broken after machine update) |
What about optionally pass a manual cache key? I'm willing to contribute this feature if it gets accepted |
@Shinigami92 , it is not something that we would like to support in scope of setup-node for now. I would suggest to use actions/cache directly for this use-case. |
Do I understand currectly that If so, wouldn't that be a good argument for taking a look at #103 again? |
I recently tried to switch from using (actions/cache)[https://github.com/actions/cache] over to actions/setup-node using the new cache functionality. However, it doesn't seem to share the cache across branches (which actions/cache does), because the first run on every branch will take ~5x longer now.
Do you have any plans on changing this? With actions/cache, this is the logic we used: - name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
${{ runner.os }}- Let me know if this is better as a separate issue. |
Hello @akd-io. You're right. It does not cache node_modules directory. Action uses Hello @sandstrom. As I checked, the default branch cache is available to other branches in setup-node. Could you please create the separate issue and provide repro steps. I can suppose that on branches you change lock files, that's why action can't get previous primary key. For now I'm closing the issue. If you have any other question feel free to ping me in the thread or create separate issue. |
I was excited to see the blog post GitHub Actions: Setup-node now supports dependency caching. However, it's not clear to me what this caching actually means. From the README:
README.md
Caching yarn dependencies:
Yarn caching handles both yarn versions: 1 or 2.
Caching can mean many things when it comes to Yarn 2, for example, these questions come to mind:
node_modules
folder cached?.yarn/cache
cached instead?~/.cache/yarn
) that is cached?Some clarifications would be appreciated 🙏.
The text was updated successfully, but these errors were encountered: