From 85924b02db7a24b9d91147d77cea3c537a2a3ddd Mon Sep 17 00:00:00 2001 From: Evgeny Kochetkov Date: Tue, 26 Jan 2021 17:49:09 +0300 Subject: [PATCH 1/5] tweak(infra): ensure 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 --- .circleci/config.yml | 4 ++ .nvmrc | 2 +- package.json | 3 ++ tools/match-node-version-to-electron.js | 55 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tools/match-node-version-to-electron.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 45f90641..a2d36c46 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -146,6 +146,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 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); + }); From 927a331c9aa4da7188ee09156cb67bc791856c19 Mon Sep 17 00:00:00 2001 From: Evgeny Kochetkov Date: Tue, 26 Jan 2021 18:31:46 +0300 Subject: [PATCH 2/5] tweak(infra): install correct version of node in windows CI --- .circleci/config.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a2d36c46..159f9158 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -75,8 +75,9 @@ defs: 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 @@ -183,9 +184,9 @@ jobs: name: win/default steps: - run: *step-configure-git-on-windows + - checkout - run: *step-install-node-on-windows - run: *step-install-yarn-on-windows - - checkout - run: name: Install Node modules command: yarn @@ -282,9 +283,9 @@ jobs: name: win/default steps: - run: *step-configure-git-on-windows + - checkout - 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 From 3467d52afc8873d2da4ba2302666110ac188ccb5 Mon Sep 17 00:00:00 2001 From: Evgeny Kochetkov Date: Tue, 26 Jan 2021 18:32:16 +0300 Subject: [PATCH 3/5] tweak(infra): use caching for node_modules in windows CI --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 159f9158..ab6cd285 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -185,11 +185,13 @@ jobs: 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 - run: name: Install Node modules command: yarn + - save_cache: *cache-node_modules - run: *step-build - run: *step-verify-git-clean @@ -284,6 +286,7 @@ jobs: 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 - run: *step-install-arduino-cli-on-windows From be8caf887175761deaf3e7a001a24af81231e5ae Mon Sep 17 00:00:00 2001 From: Evgeny Kochetkov Date: Tue, 26 Jan 2021 18:32:47 +0300 Subject: [PATCH 4/5] tweak(infra): install correct version of node in macos CI --- .circleci/config.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index ab6cd285..735ff875 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -72,6 +72,16 @@ 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: | @@ -169,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 @@ -268,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 From a3180f984d776edf356a7c8804186ccad6035e77 Mon Sep 17 00:00:00 2001 From: Evgeny Kochetkov Date: Tue, 26 Jan 2021 19:40:36 +0300 Subject: [PATCH 5/5] tweak(infra): use node 12.16.3 in linux CI images --- .circleci/Dockerfile | 2 +- .circleci/config.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 735ff875..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