Can we cache the node-modules folder to run dependencies in pipelines? #6374
-
I am writing a CI pipeline (GitHub Actions) that uses dependencies of my project (like vitest, eslint, ....) to ensure the quality of the code. All these dependencies will be run in a different job than the job that install the dependencies and runs the build. So I would rather avoid repeating the install step on each job (just do it on the job that builds the project) by caching the node-modules directory so that the dependencies are available to be used. In the pnpm documentation it's suggested to cache only the pnpm store (that's what the setup-node action does), but nothing is mentioned about the node-modules. Is there any reason why caching the node-modules directory would be a problem? By the way is pnpm/action-setup still the recommended way of setting up pnpm in a GitHub runner, or is |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Maybe, I did not think about it. You can for sure use
Caching sometimes breaks the symlinks, so if you use the default "isolated" node_modules layout, then the restored cache might not work, but I am not sure it is the case on every CI. Also, if you cache node_modules and the store separately and then run
If you won't run install again, then it might be OK. |
Beta Was this translation helpful? Give feedback.
-
If you cache just Note: important to use exact keys (not Something like this (with GH action) - name: Restore pnpm cache (if any)
id: pnpm_cache
uses: cache/restore@v4
with:
path: |
~/.cache/Cypress
node_modules
key: ${{ runner.os }}-dependencies-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Install dependencies
shell: bash
if: steps.pnpm_cache.outputs.cache-hit != 'true'
run: |
pnpm install
- name: Save pnpm cache (if changed)
uses: cache/save@v4
if: steps.pnpm_cache.outputs.cache-hit != 'true'
with:
path: |
~/.cache/Cypress
node_modules
key: ${{ steps.pnpm_cache.outputs.cache-primary-key }} |
Beta Was this translation helpful? Give feedback.
Maybe, I did not think about it. You can for sure use
corepack
instead.Caching sometimes breaks the symlinks, so if you use the default "isolated" node_modules layout, then the restored cache might not work, but I am not sure it is the case on every CI. Also, if you cache node_modules and the store separately and the…