From 7544bd3b281da12ad8d95be8f3836d0352d0ecaf Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Sat, 7 Apr 2018 08:17:34 -0700 Subject: [PATCH] further build improvements (#3315) - cache npm itself - use `npm ci` - cache the npm cache - ignore scripts when installing unless necessary - cache `node_modules` for `npm install`-using smoke tests - prefer flags over env vars Signed-off-by: Christopher Hiller --- .travis.yml | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7e9df925c..0bbb7dd2f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,10 +8,21 @@ stages: # defaults language: node_js node_js: '9' +env: PATH=~/npm/node_modules/.bin:$PATH +# `nvm install` happens before the cache is restored, which means +# we must install our own npm elsewhere (`~/npm`) +before_install: | + [[ ! -x ~/npm/node_modules/.bin/npm ]] && { + # caching feature creates `~/npm` for us + cd ~/npm && npm install npm + cd - + } || true +# this avoids compilation in most cases (where we don't need it) +install: npm ci --ignore-scripts cache: directories: - - ~/.npm - - node_modules + - ~/.npm # cache npm's cache + - ~/npm # cache latest npm jobs: include: @@ -24,18 +35,12 @@ jobs: - <<: *node node_js: '6' - cache: - directories: - - node_modules - <<: *node node_js: '4' - cache: - directories: - - node_modules - script: npm start test.bundle test.browser - before_script: mkdir -p .karma + install: npm ci # we need the native modules here addons: artifacts: paths: @@ -47,11 +52,18 @@ jobs: - stage: lint script: npm start lint + # smoke tests use default npm. - &smoke stage: smoke - env: NPM_CONFIG_PRODUCTION=1 + env: null + before_install: true + install: npm install --production + # `--opts /dev/null` means "ignore test/mocha.opts" script: ./bin/mocha --opts /dev/null --reporter spec test/sanity/sanity.spec.js - cache: false + cache: + directories: + - ~/.npm + - node_modules # npm install, unlike npm ci, doesn't wipe node_modules - <<: *smoke node_js: '8'