Skip to content

Commit c02bbb2

Browse files
committed
Simplify yarn & npm cache
Currently, we cache the entirety of node_modules. The setup-node action has caching built in, but it explicitly _does not_ cache node_modules and instead caches the global caches of npm/yarn/etc. The stated reasoning from their docs is that it allows you to maintain compatibility between different node versions. After adding support for ESLint v9 in balto-eslint, we saw an issue where linting was failing due to a module resolution issue. After using a branch with these changes, those issues went away. In this commit, we're switching from our own managed version of caching node_modules to leaning into the built-in caching from setup-node. Performance wise, it's _about_ the same when looking at the entire run. The initial install is slower, but saving the cache in the post-run step is faster. Overall, it feels like a win to reduce complexity and let setup manage the caching. As a bonus, there are currently warnings about using an outdated version of actions/cache which will be going away with this change.
1 parent 4739ab5 commit c02bbb2

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
lines changed

npm/action.yml

+3-11
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,15 @@ runs:
99
- uses: actions/setup-node@v4
1010
with:
1111
node-version: ${{ inputs.node-version }}
12-
cache: 'npm'
13-
- name: Cache node_modules
14-
id: cache-node-modules
15-
uses: actions/cache@v3
16-
with:
17-
path: node_modules
18-
key: ${{ runner.os }}-${{ inputs.node-version }}-node-modules-${{ hashFiles('**/package-lock.json') }}
19-
restore-keys: |
20-
${{ runner.os }}-${{ inputs.node-version }}-node-modules-
12+
cache: npm
13+
cache-dependency-path: "**/package-lock.json"
2114
- run: npm ci
22-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
2315
shell: bash
2416
inputs:
2517
node-version:
2618
description: Version of node to use
2719
required: false
28-
default: '18'
20+
default: "18"
2921
branding:
3022
icon: life-buoy
3123
color: orange

yarn/action.yml

+2-16
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,8 @@ runs:
99
- uses: actions/setup-node@v4
1010
with:
1111
node-version: ${{ inputs.node-version }}
12-
- name: Cache node_modules
13-
id: cache-node-modules
14-
uses: actions/cache@v3
15-
with:
16-
path: node_modules
17-
key: ${{ runner.os }}-${{ inputs.node-version }}-node-modules-${{ hashFiles('**/yarn.lock') }}
18-
restore-keys: |
19-
${{ runner.os }}-${{ inputs.node-version }}-node-modules-
20-
- name: Cache yarn cache
21-
id: cache-yarn-cache
22-
uses: actions/cache@v3
23-
with:
24-
path: .yarn/cache
25-
key: ${{ runner.os }}-${{ inputs.node-version }}-yarn-cache-${{ hashFiles('**/yarn.lock') }}
26-
restore-keys: |
27-
${{ runner.os }}-${{ inputs.node-version }}-yarn-cache-
12+
cache: yarn
13+
cache-dependency-path: "**/yarn.lock"
2814
- run: |
2915
yarn_version=$(yarn --version)
3016
major_version=$(echo "${yarn_version}" | cut -d. -f1)

0 commit comments

Comments
 (0)