diff --git a/.circleci/Dockerfile b/.circleci/Dockerfile index b69dc7ca..6994a77b 100644 --- a/.circleci/Dockerfile +++ b/.circleci/Dockerfile @@ -1,4 +1,4 @@ -FROM node:12 +FROM node:12.16.3 # Let the apt-get know we’re not interactive while building the image ARG DEBIAN_FRONTEND=noninteractive diff --git a/.circleci/config.yml b/.circleci/config.yml index 45f90641..a68b2b19 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,7 +37,7 @@ defs: machines: docker-custom-nodejs: &docker-custom-nodejs - - image: xodio/cci-node:12 + - image: xodio/cci-node:12.16.3 steps: step-install-arduino-cli-on-mac: &step-install-arduino-cli-on-mac @@ -72,11 +72,22 @@ defs: git config --global core.autocrlf input git config --system core.longpaths true + step-install-node-on-mac: &step-install-node-on-mac + name: Install node + command: | + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash + NVM_DIR="$HOME/.nvm" + echo "export NVM_DIR=\"$HOME/.nvm\"" >> $BASH_ENV + echo "[ -s \"$NVM_DIR/nvm.sh\" ] && \. \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV + \. "$NVM_DIR/nvm.sh" --no-use + nvm install + step-install-node-on-windows: &step-install-node-on-windows name: Install node command: | - nvm install 12.12.0 - nvm use 12.12.0 + nvm install `cat .nvmrc` + nvm use `cat .nvmrc` + shell: bash step-install-yarn-on-windows: &step-install-yarn-on-windows name: Install yarn @@ -146,6 +157,10 @@ jobs: - checkout - restore_cache: *restore-node_modules - run: *step-install + - run: + name: Ensure correct node versions are specified in .nvmrc and package.json + command: node ./tools/match-node-version-to-electron.js + - run: *step-verify-git-clean - run: *step-install-arduino-cli-on-linux - save_cache: *cache-node_modules - run: *step-build @@ -164,6 +179,7 @@ jobs: steps: - checkout - restore_cache: *restore-node_modules + - run: *step-install-node-on-mac - run: *step-install-arduino-cli-on-mac - run: *step-install - save_cache: *cache-node_modules @@ -179,12 +195,14 @@ jobs: name: win/default steps: - run: *step-configure-git-on-windows + - checkout + - restore_cache: *restore-node_modules - run: *step-install-node-on-windows - run: *step-install-yarn-on-windows - - checkout - run: name: Install Node modules command: yarn + - save_cache: *cache-node_modules - run: *step-build - run: *step-verify-git-clean @@ -261,6 +279,7 @@ jobs: steps: - checkout - restore_cache: *restore-node_modules + - run: *step-install-node-on-mac - run: *step-install-arduino-cli-on-mac - run: *step-install - run: *step-bump-version @@ -278,9 +297,10 @@ jobs: name: win/default steps: - run: *step-configure-git-on-windows + - checkout + - restore_cache: *restore-node_modules - run: *step-install-node-on-windows - run: *step-install-yarn-on-windows - - checkout - run: *step-install-arduino-cli-on-windows - run: name: Install Node modules diff --git a/.nvmrc b/.nvmrc index dae199ae..493319d2 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v12 +12.16.3 diff --git a/package.json b/package.json index d90f4a33..d7f9936f 100644 --- a/package.json +++ b/package.json @@ -86,5 +86,8 @@ }, "resolutions": { "**/ramda-fantasy/ramda": "^0.24.1" + }, + "engines": { + "node": "12.16.3" } } diff --git a/tools/match-node-version-to-electron.js b/tools/match-node-version-to-electron.js new file mode 100644 index 00000000..6fdbca81 --- /dev/null +++ b/tools/match-node-version-to-electron.js @@ -0,0 +1,55 @@ +#! /usr/bin/env node + +/** + * This script ensures that `engines.node` field of `package.json` + * and `.nvmrc` contain the exact same version of node.js + * that ships with the current Electron version we're using. + * + * Should be run in CI after installing node modules + * and before "verify-git-clean" step, + * or manually after updating electron. + */ + +/* eslint-disable import/no-extraneous-dependencies */ +/* eslint-disable no-console */ + +const fs = require('fs'); +const path = require('path'); +const fetch = require('node-fetch'); + +const electronVersion = require('electron/package.json').version; + +function updateEngines(nodeVersion) { + const pathToPackageJson = path.resolve(__dirname, '..', 'package.json'); + const packageJson = JSON.parse(fs.readFileSync(pathToPackageJson)); + packageJson.engines.node = nodeVersion; + fs.writeFileSync( + pathToPackageJson, + `${JSON.stringify(packageJson, null, 2)}\n` + ); +} + +function updateNvmrc(nodeVersion) { + fs.writeFileSync(path.resolve(__dirname, '..', '.nvmrc'), `${nodeVersion}\n`); +} + +fetch('https://unpkg.com/electron-releases/lite.json') + .then(response => response.json()) + .then(electronReleases => { + const release = electronReleases.find( + ({ version }) => version === electronVersion + ); + + if (!release) + throw new Error(`Can't find electron release ${electronVersion}`); + + const nodeVersion = release.deps.node; + updateNvmrc(nodeVersion); + updateEngines(nodeVersion); + + process.exit(0); + }) + .catch(err => { + console.error(err); + process.exit(1); + });