From 157d990fe006534873bc914a57b36a930e185d8c Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 17:31:11 +0000 Subject: [PATCH] chore: add a config for running CI against the nightly driver MONGOSH-1473 (#1780) * add a config for running CI against the nightly driver * add comment linking to where I got this from * log something * more intuitive name * update script comments and logging to reflect what it does * expand nightly to the exact version, force install * Update scripts/replace-package.js Co-authored-by: Anna Henningsen --------- Co-authored-by: Anna Henningsen --- .evergreen-nightly-driver.yml | 7 +++++++ .evergreen.yml | 2 ++ .evergreen/evergreen.yml.in | 2 ++ .evergreen/install-npm-deps.sh | 9 +++++++++ scripts/replace-package.js | 24 ++++++++++++++++-------- 5 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .evergreen-nightly-driver.yml diff --git a/.evergreen-nightly-driver.yml b/.evergreen-nightly-driver.yml new file mode 100644 index 000000000..ab9e5b0ea --- /dev/null +++ b/.evergreen-nightly-driver.yml @@ -0,0 +1,7 @@ +# https://github.com/evergreen-ci/evergreen/blob/main/docs/Project-Configuration/Parameterized-Builds.md#project-config +parameters: + - key: mongodb_driver_version_override + value: nightly + +include: + - filename: .evergreen.yml \ No newline at end of file diff --git a/.evergreen.yml b/.evergreen.yml index 4f3ca5cb2..720d90dfc 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -78,6 +78,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} + MONOGDB_DRIVER_VERSION_OVERRIDE: ${mongodb_driver_version_override} script: | source .evergreen/install-node.sh source .evergreen/install-npm-deps.sh @@ -114,6 +115,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} + MONOGDB_DRIVER_VERSION_OVERRIDE: ${mongodb_driver_version_override} script: | source .evergreen/install-node.sh source .evergreen/install-npm-deps.sh diff --git a/.evergreen/evergreen.yml.in b/.evergreen/evergreen.yml.in index 3889a2bb3..0012b0f8a 100644 --- a/.evergreen/evergreen.yml.in +++ b/.evergreen/evergreen.yml.in @@ -145,6 +145,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} + MONOGDB_DRIVER_VERSION_OVERRIDE: ${mongodb_driver_version_override} script: | source .evergreen/install-node.sh source .evergreen/install-npm-deps.sh @@ -181,6 +182,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} + MONOGDB_DRIVER_VERSION_OVERRIDE: ${mongodb_driver_version_override} script: | source .evergreen/install-node.sh source .evergreen/install-npm-deps.sh diff --git a/.evergreen/install-npm-deps.sh b/.evergreen/install-npm-deps.sh index abf00add8..b1b8373bb 100644 --- a/.evergreen/install-npm-deps.sh +++ b/.evergreen/install-npm-deps.sh @@ -3,6 +3,15 @@ set -x npm ci --verbose +echo "MONOGDB_DRIVER_VERSION_OVERRIDE:$MONOGDB_DRIVER_VERSION_OVERRIDE" + +# if MONOGDB_DRIVER_VERSION_OVERRIDE is set, then we want to replace the package version +if [[ -n "$MONOGDB_DRIVER_VERSION_OVERRIDE" ]]; then + export REPLACE_PACKAGE="mongodb:$MONOGDB_DRIVER_VERSION_OVERRIDE" + npm run replace-package + npm ci --verbose --force # force because of issues with peer deps and semver pre-releases +fi + # if we rewrote this script in javascript using just builtin node modules we could skip the npm ci above npm run mark-ci-required-optional-dependencies diff --git a/scripts/replace-package.js b/scripts/replace-package.js index da075596d..024c89812 100644 --- a/scripts/replace-package.js +++ b/scripts/replace-package.js @@ -1,12 +1,11 @@ -// Replace a package with symlinks to a specific directory. // Example: -// REPLACE_PACKAGE=mongodb:/home/src/node-mongodb-native node scripts/replace-package.js -// will make 'mongodb' point to '/home/src/node-mongodb-native' in the root -// directory and all lerna packages. +// REPLACE_PACKAGE=mongodb:latest node scripts/replace-package.js +// will replace the 'mongodb' dep's version with latest in the root directory +// and all packages. 'use strict'; const fs = require('fs'); const path = require('path'); -const { pathToFileURL } = require('url'); +const { execSync } = require('child_process'); const replacement = process.env.REPLACE_PACKAGE; if (!replacement) { @@ -17,11 +16,20 @@ if (!parsed || !parsed.groups.from || !parsed.groups.to) { throw new Error('Invalid format for REPLACE_PACKAGE'); } -const { from, to } = parsed.groups; +function resolveTag(from, to) { + return execSync(`npm dist-tag ls '${from}@${to}' | awk -F ': ' '/^${to}/ {print \$2}'`).toString().trim(); +} + +const { from, to: _to } = parsed.groups; + +// npm install doesn't seem to do anything if you're updating a +// package-lock.json file that already has the dep to a tag like nightly, but it +// does do something if you change it to the exact version. +const to = _to === 'nightly' ? resolveTag(from, _to) : _to; + for (const dir of ['.', ...fs.readdirSync('packages').map(dir => path.join('packages', dir))]) { const packageJson = path.join(dir, 'package.json'); if (fs.existsSync(packageJson)) { - const target = pathToFileURL(path.resolve(to)).href; const contents = JSON.parse(fs.readFileSync(packageJson)); for (const deps of [ contents.dependencies, @@ -29,7 +37,7 @@ for (const dir of ['.', ...fs.readdirSync('packages').map(dir => path.join('pack contents.optionalDependencies ]) { if (deps && deps[from]) { - console.info('Replacing', from, 'in', dir, 'with', target); + console.info(`Replacing deps[${from}]: ${deps[from]} with ${to}`); deps[from] = to; } }