From c0db900d94f5a64a87556ef7a9668e7fe0662c58 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 11:25:46 +0000 Subject: [PATCH 1/7] add a config for running CI against the nightly driver --- .evergreen-nightly-driver.yml | 6 ++++++ .evergreen.yml | 2 ++ .evergreen/evergreen.yml.in | 2 ++ .evergreen/install-npm-deps.sh | 6 ++++++ 4 files changed, 16 insertions(+) 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..f71fa6205 --- /dev/null +++ b/.evergreen-nightly-driver.yml @@ -0,0 +1,6 @@ +parameters: + - key: mongodb_version_override + value: nightly + +include: + - filename: .evergreen.yml \ No newline at end of file diff --git a/.evergreen.yml b/.evergreen.yml index 4f3ca5cb2..eb9f47fa4 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -78,6 +78,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} + MONOGDB_VERSION_OVERRIDE: ${mongodb_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_VERSION_OVERRIDE: ${mongodb_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..951e95322 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_VERSION_OVERRIDE: ${mongodb_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_VERSION_OVERRIDE: ${mongodb_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..357394434 100644 --- a/.evergreen/install-npm-deps.sh +++ b/.evergreen/install-npm-deps.sh @@ -3,6 +3,12 @@ set -x npm ci --verbose +# if MONOGDB_VERSION_OVERRIDE is set, then we want to replace the package version +if [[ -n "$MONOGDB_VERSION_OVERRIDE" ]]; then + export REPLACE_PACKAGE="mongodb:$MONOGDB_VERSION_OVERRIDE" + npm run replace-package +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 From 63b3f18fb242d0c6e573f524a555ffcd72bb4227 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 11:50:24 +0000 Subject: [PATCH 2/7] add comment linking to where I got this from --- .evergreen-nightly-driver.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.evergreen-nightly-driver.yml b/.evergreen-nightly-driver.yml index f71fa6205..2e832cc9f 100644 --- a/.evergreen-nightly-driver.yml +++ b/.evergreen-nightly-driver.yml @@ -1,3 +1,4 @@ +# https://github.com/evergreen-ci/evergreen/blob/main/docs/Project-Configuration/Parameterized-Builds.md#project-config parameters: - key: mongodb_version_override value: nightly From 34e289c08c14cef2c37c6a3a3ec26a328c55539b Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 11:51:48 +0000 Subject: [PATCH 3/7] log something --- .evergreen/install-npm-deps.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.evergreen/install-npm-deps.sh b/.evergreen/install-npm-deps.sh index 357394434..e1d5d3683 100644 --- a/.evergreen/install-npm-deps.sh +++ b/.evergreen/install-npm-deps.sh @@ -3,6 +3,8 @@ set -x npm ci --verbose +echo "MONOGDB_VERSION_OVERRIDE:$MONOGDB_VERSION_OVERRIDE" + # if MONOGDB_VERSION_OVERRIDE is set, then we want to replace the package version if [[ -n "$MONOGDB_VERSION_OVERRIDE" ]]; then export REPLACE_PACKAGE="mongodb:$MONOGDB_VERSION_OVERRIDE" From 1b626f146f4daffdd02a5d609bd932b9ae79aedd Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 13:21:58 +0000 Subject: [PATCH 4/7] more intuitive name --- .evergreen-nightly-driver.yml | 2 +- .evergreen.yml | 4 ++-- .evergreen/evergreen.yml.in | 4 ++-- .evergreen/install-npm-deps.sh | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.evergreen-nightly-driver.yml b/.evergreen-nightly-driver.yml index 2e832cc9f..ab9e5b0ea 100644 --- a/.evergreen-nightly-driver.yml +++ b/.evergreen-nightly-driver.yml @@ -1,6 +1,6 @@ # https://github.com/evergreen-ci/evergreen/blob/main/docs/Project-Configuration/Parameterized-Builds.md#project-config parameters: - - key: mongodb_version_override + - key: mongodb_driver_version_override value: nightly include: diff --git a/.evergreen.yml b/.evergreen.yml index eb9f47fa4..720d90dfc 100644 --- a/.evergreen.yml +++ b/.evergreen.yml @@ -78,7 +78,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} - MONOGDB_VERSION_OVERRIDE: ${mongodb_version_override} + MONOGDB_DRIVER_VERSION_OVERRIDE: ${mongodb_driver_version_override} script: | source .evergreen/install-node.sh source .evergreen/install-npm-deps.sh @@ -115,7 +115,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} - MONOGDB_VERSION_OVERRIDE: ${mongodb_version_override} + 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 951e95322..0012b0f8a 100644 --- a/.evergreen/evergreen.yml.in +++ b/.evergreen/evergreen.yml.in @@ -145,7 +145,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} - MONOGDB_VERSION_OVERRIDE: ${mongodb_version_override} + MONOGDB_DRIVER_VERSION_OVERRIDE: ${mongodb_driver_version_override} script: | source .evergreen/install-node.sh source .evergreen/install-npm-deps.sh @@ -182,7 +182,7 @@ functions: env: NODE_JS_VERSION: ${node_js_version} DISTRO_ID: ${distro_id} - MONOGDB_VERSION_OVERRIDE: ${mongodb_version_override} + 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 e1d5d3683..88846145e 100644 --- a/.evergreen/install-npm-deps.sh +++ b/.evergreen/install-npm-deps.sh @@ -3,11 +3,11 @@ set -x npm ci --verbose -echo "MONOGDB_VERSION_OVERRIDE:$MONOGDB_VERSION_OVERRIDE" +echo "MONOGDB_DRIVER_VERSION_OVERRIDE:$MONOGDB_DRIVER_VERSION_OVERRIDE" -# if MONOGDB_VERSION_OVERRIDE is set, then we want to replace the package version -if [[ -n "$MONOGDB_VERSION_OVERRIDE" ]]; then - export REPLACE_PACKAGE="mongodb:$MONOGDB_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 fi From 3ccb9008914cd0f3dbfdbba500b34d84600204d8 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 14:16:17 +0000 Subject: [PATCH 5/7] update script comments and logging to reflect what it does --- scripts/replace-package.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/replace-package.js b/scripts/replace-package.js index da075596d..d4db2fc16 100644 --- a/scripts/replace-package.js +++ b/scripts/replace-package.js @@ -1,12 +1,10 @@ -// 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 replacement = process.env.REPLACE_PACKAGE; if (!replacement) { @@ -21,7 +19,6 @@ const { from, to } = parsed.groups; 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 +26,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; } } From 226503e0e670848460895725940508854166f0d4 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 15:38:52 +0000 Subject: [PATCH 6/7] expand nightly to the exact version, force install --- .evergreen/install-npm-deps.sh | 1 + scripts/replace-package.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.evergreen/install-npm-deps.sh b/.evergreen/install-npm-deps.sh index 88846145e..b1b8373bb 100644 --- a/.evergreen/install-npm-deps.sh +++ b/.evergreen/install-npm-deps.sh @@ -9,6 +9,7 @@ echo "MONOGDB_DRIVER_VERSION_OVERRIDE:$MONOGDB_DRIVER_VERSION_OVERRIDE" 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 diff --git a/scripts/replace-package.js b/scripts/replace-package.js index d4db2fc16..9f2262d98 100644 --- a/scripts/replace-package.js +++ b/scripts/replace-package.js @@ -5,6 +5,7 @@ 'use strict'; const fs = require('fs'); const path = require('path'); +const { execSync } = require('child_process'); const replacement = process.env.REPLACE_PACKAGE; if (!replacement) { @@ -15,7 +16,17 @@ 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)) { From cc99718a5d385fe7eecec5f2a64489b324041ef6 Mon Sep 17 00:00:00 2001 From: Le Roux Bodenstein Date: Mon, 8 Jan 2024 16:02:16 +0000 Subject: [PATCH 7/7] Update scripts/replace-package.js Co-authored-by: Anna Henningsen --- scripts/replace-package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/replace-package.js b/scripts/replace-package.js index 9f2262d98..024c89812 100644 --- a/scripts/replace-package.js +++ b/scripts/replace-package.js @@ -17,7 +17,7 @@ if (!parsed || !parsed.groups.from || !parsed.groups.to) { } function resolveTag(from, to) { - return execSync(`npm dist-tag ls ${from}@${to} | awk -F ': ' '/^${to}/ {print \$2}'`).toString().trim(); + return execSync(`npm dist-tag ls '${from}@${to}' | awk -F ': ' '/^${to}/ {print \$2}'`).toString().trim(); } const { from, to: _to } = parsed.groups;