Skip to content

Commit

Permalink
Switch from "npm ci" to "npm install" for CI (#719)
Browse files Browse the repository at this point in the history
* Switch from "npm ci" to "npm install" for CI

**Why**: Because "npm ci" ignores and destroys the cached node_modules and is otherwise difficult to cache. "npm install" should behave similar, respect package-lock.json, hydrate from cache. The other behavior of "npm ci" of validating package-lock.json isn't always reliable, and is replicated here with check-lockfiles, largely copied from similar scripts in identity-style-guide and identity-idp.

* Run the right validation command

Co-authored-by: Zach Margolis <[email protected]>

* Fix env var condition

**Why**: Was previously always skipping

Co-authored-by: Zach Margolis <[email protected]>
  • Loading branch information
aduth and zachmargolis authored Nov 3, 2021
1 parent cb65d11 commit 7a5ef1b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
15 changes: 14 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ commands:
name: install dependencies
command: |
sudo npm install -g n && sudo n 12
npm ci
npm install
bundle check || bundle install --jobs=4 --retry=3 --path vendor/bundle
- save_cache:
paths:
Expand Down Expand Up @@ -100,6 +100,18 @@ jobs:
name: check optimized images
command: make lint-assets

check-lockfiles:
docker:
- image: cimg/ruby:2.7-node
environment:
SKIP_INSTALL: true
steps:
- checkout
- install-dependencies
- run:
name: check lockfile differences
command: make validate-lockfiles

check-javascript-syntax:
docker:
- image: cimg/ruby:2.7-node
Expand Down Expand Up @@ -137,6 +149,7 @@ workflows:
- build
- eslint
- check-optimized-assets
- check-lockfiles
- test:
requires:
- build
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lint-assets:
npm run viewbox || (echo "Make sure all SVG images have a viewBox attribute"; exit 1)
git diff --quiet assets/img || (echo "Error: Optimize SVG images using 'npm run optimize-assets'"; exit 1)

lint: lint-js lint-assets
lint: lint-js lint-assets validate-lockfiles

test: build
bundle exec rspec spec
Expand All @@ -30,3 +30,15 @@ htmlproofer:
build:
npm run build-js
bundle exec jekyll build

validate-gemfile-lock: Gemfile Gemfile.lock
@echo "Validating Gemfile.lock..."
@bundle check
@git diff-index --quiet HEAD Gemfile.lock || (echo "Error: There are uncommitted changes after running 'bundle install'"; exit 1)

validate-package-lock: package.json package-lock.json
@echo "Validating package-lock.json..."
@[[ -z $$SKIP_INSTALL ]] && npm install --ignore-scripts || exit 0
@(! git diff --name-only | grep package-lock.json) || (echo "Error: There are uncommitted changes after running 'npm install'"; exit 1)

validate-lockfiles: validate-gemfile-lock validate-package-lock

0 comments on commit 7a5ef1b

Please sign in to comment.