Merge pull request #2093 from xodio/pin-node-version

Pin node versions in CircleCI runners.
This commit is contained in:
Evgeny Kochetkov
2021-01-27 15:15:46 +03:00
committed by GitHub
5 changed files with 85 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
FROM node:12
FROM node:12.16.3
# Let the apt-get know were not interactive while building the image
ARG DEBIAN_FRONTEND=noninteractive

View File

@@ -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

2
.nvmrc
View File

@@ -1 +1 @@
v12
12.16.3

View File

@@ -86,5 +86,8 @@
},
"resolutions": {
"**/ramda-fantasy/ramda": "^0.24.1"
},
"engines": {
"node": "12.16.3"
}
}

View File

@@ -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);
});