Skip to content

Commit

Permalink
chore: add a config for running CI against the nightly driver MONGOSH…
Browse files Browse the repository at this point in the history
…-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 <[email protected]>

---------

Co-authored-by: Anna Henningsen <[email protected]>
  • Loading branch information
lerouxb and addaleax authored Jan 8, 2024
1 parent aca42db commit 157d990
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .evergreen-nightly-driver.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .evergreen/evergreen.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions .evergreen/install-npm-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 16 additions & 8 deletions scripts/replace-package.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -17,19 +16,28 @@ 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,
contents.devDependencies,
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;
}
}
Expand Down

0 comments on commit 157d990

Please sign in to comment.