Skip to content

Commit

Permalink
ci: use npm ci and do not cache workspace packages in node_modules
Browse files Browse the repository at this point in the history
Previously we were caching all the `node_modules` files in the CI jobs and then running `npm install`. While this resulted in slightly improved install times on Ubuntu, it breaks on Windows because the npm workspace setup adds symlinks into node_modules, which the Github cache action cannot cope with.

This change removes the `node_modules` caches (saving some time by not needing to restore them) and replaces `npm install` with `npm ci`.

The `npm ci` command is actually designed to be used in CI jobs as it only installs the exact versions specified in the `package-lock.json` file, guaranteeing that for any commit we always have exactly the same CI job run, deterministically.

It turns out that, on Ubuntu, using `npm ci` makes very little difference to the installation time (~30 secs), especially if there is no `node_modules` there in the first place.

Unfortunately, MacOS is slower (~1 min), and Windows even worse (~2 mins)! But it is worth this longer CI run to be sure we have things working on all OSes.
  • Loading branch information
petebacondarwin committed Feb 1, 2022
1 parent ac2d7e7 commit ecacf92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
15 changes: 15 additions & 0 deletions .changeset/tough-countries-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"wrangler": patch
---

ci: use `npm ci` and do not cache workspace packages in node_modules

Previously we were caching all the `node_modules` files in the CI jobs and then running `npm install`. While this resulted in slightly improved install times on Ubuntu, it breaks on Windows because the npm workspace setup adds symlinks into node_modules, which the Github cache action cannot cope with.

This change removes the `node_modules` caches (saving some time by not needing to restore them) and replaces `npm install` with `npm ci`.

The `npm ci` command is actually designed to be used in CI jobs as it only installs the exact versions specified in the `package-lock.json` file, guaranteeing that for any commit we always have exactly the same CI job run, deterministically.

It turns out that, on Ubuntu, using `npm ci` makes very little difference to the installation time (~30 secs), especially if there is no `node_modules` there in the first place.

Unfortunately, MacOS is slower (~1 min), and Windows even worse (~2 mins)! But it is worth this longer CI run to be sure we have things working on all OSes.
20 changes: 2 additions & 18 deletions .github/workflows/pullrequests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ jobs:
node-version: 16.7
cache: "npm"

- uses: actions/cache@v2
id: node-modules-cache
with:
path: |
node_modules
*/*/node_modules
key: ${{ matrix.os }}-node-${{ hashFiles('**/package-lock.json') }}

- uses: actions/cache@v2
id: eslint-cache
with:
Expand All @@ -38,7 +30,7 @@ jobs:
key: ${{ matrix.os }}-eslint-tsbuildinfo-${{ hashFiles('**/*.ts','**/*.js', 'package.json', 'tsconfig.json') }}

- name: Install NPM Dependencies
run: npm install
run: npm ci

- name: Check for errors
run: npm run check
Expand All @@ -61,16 +53,8 @@ jobs:
node-version: 16.7
cache: "npm"

- uses: actions/cache@v2
id: node-modules-cache
with:
path: |
node_modules
*/*/node_modules
key: ${{ matrix.os }}-node-${{ hashFiles('**/package-lock.json') }}

- name: Install NPM Dependencies
run: npm install
run: npm ci

- name: Run build and test
run: npm run build-and-test

0 comments on commit ecacf92

Please sign in to comment.