From 87d947dc31c68333fe95b090abe3671bc418bcdf Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 6 Jun 2023 11:40:36 -0600 Subject: [PATCH 1/3] rename init-nvm script --- .evergreen/{init-nvm.sh => init-node-and-npm-env.sh} | 0 .evergreen/run-atlas-tests.sh | 2 +- .evergreen/run-benchmarks.sh | 2 +- .evergreen/run-bson-ext-test.sh | 2 +- .evergreen/run-custom-csfle-tests.sh | 2 +- .evergreen/run-data-lake-tests.sh | 2 +- .evergreen/run-kerberos-tests.sh | 2 +- .evergreen/run-lambda-aws-tests.sh | 2 +- .evergreen/run-lambda-tests.sh | 2 +- .evergreen/run-ldap-tests.sh | 2 +- .evergreen/run-lint-checks.sh | 2 +- .evergreen/run-mongodb-aws-ecs-test.sh | 2 +- .evergreen/run-mongodb-aws-test.sh | 2 +- .evergreen/run-mongosh-integration-tests.sh | 2 +- .evergreen/run-mongosh-scope-test.sh | 2 +- .evergreen/run-ocsp-tests.sh | 2 +- .evergreen/run-snappy-version-test.sh | 2 +- .evergreen/run-socks5-tests.sh | 2 +- .evergreen/run-tests.sh | 2 +- .evergreen/run-tls-tests.sh | 2 +- .evergreen/run-typescript.sh | 2 +- .evergreen/run-unit-tests.sh | 2 +- 22 files changed, 21 insertions(+), 21 deletions(-) rename .evergreen/{init-nvm.sh => init-node-and-npm-env.sh} (100%) diff --git a/.evergreen/init-nvm.sh b/.evergreen/init-node-and-npm-env.sh similarity index 100% rename from .evergreen/init-nvm.sh rename to .evergreen/init-node-and-npm-env.sh diff --git a/.evergreen/run-atlas-tests.sh b/.evergreen/run-atlas-tests.sh index aa675faa413..c65b8512a77 100644 --- a/.evergreen/run-atlas-tests.sh +++ b/.evergreen/run-atlas-tests.sh @@ -2,7 +2,7 @@ set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -o xtrace diff --git a/.evergreen/run-benchmarks.sh b/.evergreen/run-benchmarks.sh index d8347077a86..8e1bf318996 100644 --- a/.evergreen/run-benchmarks.sh +++ b/.evergreen/run-benchmarks.sh @@ -1,6 +1,6 @@ #! /bin/bash -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" export MONGODB_URI=$MONGODB_URI diff --git a/.evergreen/run-bson-ext-test.sh b/.evergreen/run-bson-ext-test.sh index 7b491847836..fdaabfe6cd4 100755 --- a/.evergreen/run-bson-ext-test.sh +++ b/.evergreen/run-bson-ext-test.sh @@ -1,6 +1,6 @@ #!/bin/bash -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -o xtrace # Write all commands first to stderr set -o errexit # Exit the script with error if any of the commands fail diff --git a/.evergreen/run-custom-csfle-tests.sh b/.evergreen/run-custom-csfle-tests.sh index 957f5386fbd..018fe5974ad 100644 --- a/.evergreen/run-custom-csfle-tests.sh +++ b/.evergreen/run-custom-csfle-tests.sh @@ -12,7 +12,7 @@ export CSFLE_KMS_PROVIDERS=${CSFLE_KMS_PROVIDERS} export CRYPT_SHARED_LIB_PATH=${CRYPT_SHARED_LIB_PATH} echo "csfle CRYPT_SHARED_LIB_PATH: $CRYPT_SHARED_LIB_PATH" -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -o xtrace # Write all commands first to stderr set -o errexit # Exit the script with error if any of the commands fail diff --git a/.evergreen/run-data-lake-tests.sh b/.evergreen/run-data-lake-tests.sh index ebab0899ea6..8f62a1f16aa 100644 --- a/.evergreen/run-data-lake-tests.sh +++ b/.evergreen/run-data-lake-tests.sh @@ -2,7 +2,7 @@ set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" echo "$MONGODB_URI" npm run check:adl diff --git a/.evergreen/run-kerberos-tests.sh b/.evergreen/run-kerberos-tests.sh index 1c2b6d3b5f6..dd1e0c4c36d 100644 --- a/.evergreen/run-kerberos-tests.sh +++ b/.evergreen/run-kerberos-tests.sh @@ -2,7 +2,7 @@ set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" # set up keytab mkdir -p "$(pwd)/.evergreen" diff --git a/.evergreen/run-lambda-aws-tests.sh b/.evergreen/run-lambda-aws-tests.sh index ec0a24c200f..685d1781825 100644 --- a/.evergreen/run-lambda-aws-tests.sh +++ b/.evergreen/run-lambda-aws-tests.sh @@ -8,7 +8,7 @@ MONGODB_URI=${MONGODB_URI:-} set +x # load node.js environment -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" # the default connection string, may be overridden by the environment script export MONGODB_URI="mongodb://localhost:27017/aws" diff --git a/.evergreen/run-lambda-tests.sh b/.evergreen/run-lambda-tests.sh index 6b632984fb2..be7101a188d 100644 --- a/.evergreen/run-lambda-tests.sh +++ b/.evergreen/run-lambda-tests.sh @@ -8,6 +8,6 @@ MONGODB_URI=${MONGODB_URI:-} set +x # load node.js environment -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" npm run check:lambda diff --git a/.evergreen/run-ldap-tests.sh b/.evergreen/run-ldap-tests.sh index 10725da1b62..3354aab3038 100644 --- a/.evergreen/run-ldap-tests.sh +++ b/.evergreen/run-ldap-tests.sh @@ -2,6 +2,6 @@ set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" npm run check:ldap diff --git a/.evergreen/run-lint-checks.sh b/.evergreen/run-lint-checks.sh index fac14cef0dc..1c57972c316 100644 --- a/.evergreen/run-lint-checks.sh +++ b/.evergreen/run-lint-checks.sh @@ -1,7 +1,7 @@ #!/bin/bash set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" # Attempt to update our EVG config # if it changes, crash so that any gen script changes are forced to be run before pushing diff --git a/.evergreen/run-mongodb-aws-ecs-test.sh b/.evergreen/run-mongodb-aws-ecs-test.sh index e133a49fe77..c0844d2c060 100755 --- a/.evergreen/run-mongodb-aws-ecs-test.sh +++ b/.evergreen/run-mongodb-aws-ecs-test.sh @@ -11,7 +11,7 @@ tar -xzf src.tgz . # load node.js set +x -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -x # run the tests diff --git a/.evergreen/run-mongodb-aws-test.sh b/.evergreen/run-mongodb-aws-test.sh index 84389e3ed70..b5fa843f20c 100755 --- a/.evergreen/run-mongodb-aws-test.sh +++ b/.evergreen/run-mongodb-aws-test.sh @@ -8,7 +8,7 @@ MONGODB_URI=${MONGODB_URI:-} set +x # load node.js environment -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" # the default connection string, may be overridden by the environment script export MONGODB_URI="mongodb://localhost:27017/aws?authMechanism=MONGODB-AWS" diff --git a/.evergreen/run-mongosh-integration-tests.sh b/.evergreen/run-mongosh-integration-tests.sh index 40ee5d08324..2d3ff53beb0 100644 --- a/.evergreen/run-mongosh-integration-tests.sh +++ b/.evergreen/run-mongosh-integration-tests.sh @@ -16,7 +16,7 @@ if [ -z ${TASK_ID+omitted} ]; then echo "TASK_ID is unset" && exit 1; fi MONGOSH_RUN_ONLY_IN_PACKAGE=${MONGOSH_RUN_ONLY_IN_PACKAGE:-""} -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" npm cache clear --force || true npm i -g npm@8.x || true diff --git a/.evergreen/run-mongosh-scope-test.sh b/.evergreen/run-mongosh-scope-test.sh index 64886f608d1..99345bc0acb 100644 --- a/.evergreen/run-mongosh-scope-test.sh +++ b/.evergreen/run-mongosh-scope-test.sh @@ -2,7 +2,7 @@ if [ -z ${TASK_ID+omitted} ]; then echo "TASK_ID is unset" && exit 1; fi -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" MONGOSH_DIRECTORY="/tmp/$TASK_ID" git clone --depth=10 https://github.com/mongodb-js/mongosh.git $MONGOSH_DIRECTORY diff --git a/.evergreen/run-ocsp-tests.sh b/.evergreen/run-ocsp-tests.sh index 4f96b1e86b4..a9006714e32 100644 --- a/.evergreen/run-ocsp-tests.sh +++ b/.evergreen/run-ocsp-tests.sh @@ -3,7 +3,7 @@ set -o xtrace set -o errexit # load node.js environment -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" # $PYTHON_BINARY -m virtualenv --never-download --no-wheel ocsptest # . ocsptest/bin/activate diff --git a/.evergreen/run-snappy-version-test.sh b/.evergreen/run-snappy-version-test.sh index 15df4a577d9..54dddc6a19a 100644 --- a/.evergreen/run-snappy-version-test.sh +++ b/.evergreen/run-snappy-version-test.sh @@ -1,6 +1,6 @@ #! /usr/bin/env bash -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" export MONGODB_URI="${MONGODB_URI}" npm i --no-save snappy@6 diff --git a/.evergreen/run-socks5-tests.sh b/.evergreen/run-socks5-tests.sh index 5924a10d7ab..6e0e8aa3452 100644 --- a/.evergreen/run-socks5-tests.sh +++ b/.evergreen/run-socks5-tests.sh @@ -1,6 +1,6 @@ #!/bin/bash -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -o errexit # Exit the script with error if any of the commands fail set -o xtrace # For debuggability, no external credentials are used here diff --git a/.evergreen/run-tests.sh b/.evergreen/run-tests.sh index 4b09680ad96..38896706061 100755 --- a/.evergreen/run-tests.sh +++ b/.evergreen/run-tests.sh @@ -29,7 +29,7 @@ echo "Running $AUTH tests over $SSL, connecting to $MONGODB_URI" if [[ -z "${SKIP_DEPS}" ]]; then source "${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh" else - source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" + source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" fi if [ "$COMPRESSOR" != "" ]; then diff --git a/.evergreen/run-tls-tests.sh b/.evergreen/run-tls-tests.sh index c8c3e83dc6f..f5f30af7164 100644 --- a/.evergreen/run-tls-tests.sh +++ b/.evergreen/run-tls-tests.sh @@ -2,7 +2,7 @@ set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" export SSL_KEY_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/client.pem" export SSL_CA_FILE="$DRIVERS_TOOLS/.evergreen/x509gen/ca.pem" diff --git a/.evergreen/run-typescript.sh b/.evergreen/run-typescript.sh index 594aa29e123..703f86ab240 100644 --- a/.evergreen/run-typescript.sh +++ b/.evergreen/run-typescript.sh @@ -1,7 +1,7 @@ #!/bin/bash set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -o xtrace diff --git a/.evergreen/run-unit-tests.sh b/.evergreen/run-unit-tests.sh index e4d8f36f6c6..a1ab8e3a1a1 100644 --- a/.evergreen/run-unit-tests.sh +++ b/.evergreen/run-unit-tests.sh @@ -1,7 +1,7 @@ #!/bin/bash set -o errexit # Exit the script with error if any of the commands fail -source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh" +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" set -o xtrace npx nyc npm run check:unit From 4fe5bb3ae586084f32c8e092df6937c10d98834b Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 6 Jun 2023 11:42:30 -0600 Subject: [PATCH 2/3] apply changes --- .evergreen/init-node-and-npm-env.sh | 14 +++++++++++--- .evergreen/install-dependencies.sh | 20 +++++++------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.evergreen/init-node-and-npm-env.sh b/.evergreen/init-node-and-npm-env.sh index 28d14f16d83..b3cecf54e33 100644 --- a/.evergreen/init-node-and-npm-env.sh +++ b/.evergreen/init-node-and-npm-env.sh @@ -1,13 +1,21 @@ #! /usr/bin/env bash - -export PATH="/opt/mongodbtoolchain/v2/bin:$PATH" +## +## This script add the location of `npm` and `node` to the path. +## This is necessary because evergreen uses separate bash scripts for +## different functions in a given CI run but doesn't persist the environment +## across them. So we manually invoke this script everywhere we need +## access to `npm`, `node`, or need to install something globally from +## npm. NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts" if [[ "$OS" == "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH") fi -export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH" +export NODE_ARTIFACTS_PATH +# npm uses this environment variable to determine where to install global packages +export npm_global_prefix=$NODE_ARTIFACTS_PATH/npm_global +export PATH="$npm_global_prefix/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH" hash -r export NODE_OPTIONS="--trace-deprecation --trace-warnings" diff --git a/.evergreen/install-dependencies.sh b/.evergreen/install-dependencies.sh index 8faa962da0e..12995a43cf1 100644 --- a/.evergreen/install-dependencies.sh +++ b/.evergreen/install-dependencies.sh @@ -2,8 +2,8 @@ set -o errexit # Exit the script with error if any of the commands fail NODE_LTS_VERSION=${NODE_LTS_VERSION:-12} -NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts" -if [[ "$OS" = "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH"); fi + +source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" CURL_FLAGS=( --fail # Exit code 1 if request fails @@ -90,25 +90,19 @@ else mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs" fi -export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH" -hash -r - -# Set npm -g prefix to our local artifacts directory -cat < .npmrc -prefix=$NODE_ARTIFACTS_PATH/npm_global -EOT +if [[ -z "${npm_global_prefix}" ]]; then + echo "npm_prefix_config not set" + exit 1 +fi # Cannot upgrade npm version for node 12 if [[ $operating_system != "win" ]] && [[ $NODE_LTS_VERSION != 12 ]]; then # Update npm to latest when we can npm install --global npm@latest hash -r -elif [[ $NODE_LTS_VERSION == 12 ]]; then - # Node.js 12 can run up to npm v8 - npm install --global npm@8 - hash -r fi +echo "npm location: $(which npm)" echo "npm version: $(npm -v)" npm install "${NPM_OPTIONS}" From 6ff3834b5b0ef9e9ec82f48ea92577352c6d8381 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 8 Jun 2023 08:06:02 -0600 Subject: [PATCH 3/3] add guards to install script --- .evergreen/install-dependencies.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.evergreen/install-dependencies.sh b/.evergreen/install-dependencies.sh index 12995a43cf1..9132237a676 100644 --- a/.evergreen/install-dependencies.sh +++ b/.evergreen/install-dependencies.sh @@ -5,6 +5,9 @@ NODE_LTS_VERSION=${NODE_LTS_VERSION:-12} source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh" +if [[ -z "${npm_global_prefix}" ]]; then echo "npm_global_prefix is unset" && exit 1; fi +if [[ -z "${NODE_ARTIFACTS_PATH}" ]]; then echo "NODE_ARTIFACTS_PATH is unset" && exit 1; fi + CURL_FLAGS=( --fail # Exit code 1 if request fails --compressed # Request a compressed response should keep fetching fast @@ -90,11 +93,6 @@ else mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs" fi -if [[ -z "${npm_global_prefix}" ]]; then - echo "npm_prefix_config not set" - exit 1 -fi - # Cannot upgrade npm version for node 12 if [[ $operating_system != "win" ]] && [[ $NODE_LTS_VERSION != 12 ]]; then # Update npm to latest when we can