Skip to content

The agent that grows with you

ci(js-tests): cache the installed node_modules tree, not just the npm tarball cache

kshitijf56a9a1185bb
diff --git a/.github/workflows/js-tests.yml b/.github/workflows/js-tests.yml
index 9119e0c7a9b..1e5bdfc773c 100644
--- a/.github/workflows/js-tests.yml
+++ b/.github/workflows/js-tests.yml
@@ -22,7 +22,29 @@ jobs:
run: |
npm i -g npm@12
+ # ``setup-node``'s ``cache: npm`` only caches the ~/.npm tarball cache;
+ # every job still re-extracts the full workspace node_modules and reruns
+ # postinstalls (including the Electron binary fetch). Cache the installed
+ # tree itself, keyed on the lockfile, and skip ``npm ci`` on an exact
+ # hit. No restore-keys: a partial hit would leave a stale tree, so
+ # anything but an exact lockfile match reinstalls from scratch.
+ # The discovery job installs with --ignore-scripts, so its tree differs
+ # from the check jobs' — hence the distinct ``-noscripts`` key.
+ - name: Restore node_modules
+ id: node-modules-cache
+ uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
+ with:
+ path: |
+ node_modules
+ apps/*/node_modules
+ ui-tui/node_modules
+ ui-tui/packages/*/node_modules
+ tests-js/node_modules
+ web/node_modules
+ key: node-modules-noscripts-${{ runner.os }}-node26-npm12-${{ hashFiles('package-lock.json') }}
+
- uses: ./.github/actions/retry
+ if: steps.node-modules-cache.outputs.cache-hit != 'true'
with:
command: npm ci --ignore-scripts
- id: set-matrix
@@ -73,7 +95,26 @@ jobs:
run: |
npm i -g npm@12
+ # Same rationale as the discovery job's cache above, but this ``npm ci``
+ # runs WITH install scripts, so the tree includes postinstall artifacts
+ # and the Electron binary is fetched to ~/.cache/electron — cache both
+ # under a key distinct from the -noscripts one.
+ - name: Restore node_modules
+ id: node-modules-cache
+ uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
+ with:
+ path: |
+ node_modules
+ apps/*/node_modules
+ ui-tui/node_modules
+ ui-tui/packages/*/node_modules
+ tests-js/node_modules
+ web/node_modules
+ ~/.cache/electron
+ key: node-modules-scripts-${{ runner.os }}-node26-npm12-${{ hashFiles('package-lock.json') }}
+
- uses: ./.github/actions/retry
+ if: steps.node-modules-cache.outputs.cache-hit != 'true'
with:
command: npm ci
- run: npm run --prefix ${{ matrix.package }} ${{ matrix.script }}