From 7f5b334ce7efcf5c2c2417951e275b86def23284 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 8 Jun 2023 09:35:56 -0600 Subject: [PATCH] ci(NODE-5334): install npm to node_artifacts directory in CI (#3709) --- .evergreen/init-node-and-npm-env.sh | 21 +++++++++++++++++++++ .evergreen/init-nvm.sh | 13 ------------- .evergreen/install-dependencies.sh | 20 ++++++-------------- .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 +- 24 files changed, 48 insertions(+), 48 deletions(-) create mode 100644 .evergreen/init-node-and-npm-env.sh delete mode 100644 .evergreen/init-nvm.sh diff --git a/.evergreen/init-node-and-npm-env.sh b/.evergreen/init-node-and-npm-env.sh new file mode 100644 index 0000000000..b3cecf54e3 --- /dev/null +++ b/.evergreen/init-node-and-npm-env.sh @@ -0,0 +1,21 @@ +#! /usr/bin/env bash +## +## 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 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/init-nvm.sh b/.evergreen/init-nvm.sh deleted file mode 100644 index 28d14f16d8..0000000000 --- a/.evergreen/init-nvm.sh +++ /dev/null @@ -1,13 +0,0 @@ -#! /usr/bin/env bash - -export PATH="/opt/mongodbtoolchain/v2/bin:$PATH" - -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" -hash -r - -export NODE_OPTIONS="--trace-deprecation --trace-warnings" diff --git a/.evergreen/install-dependencies.sh b/.evergreen/install-dependencies.sh index 8faa962da0..9132237a67 100644 --- a/.evergreen/install-dependencies.sh +++ b/.evergreen/install-dependencies.sh @@ -2,8 +2,11 @@ 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" + +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 @@ -90,25 +93,14 @@ 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 - # 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}" diff --git a/.evergreen/run-atlas-tests.sh b/.evergreen/run-atlas-tests.sh index aa675faa41..c65b8512a7 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 d8347077a8..8e1bf31899 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 7b49184783..fdaabfe6cd 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 957f5386fb..018fe5974a 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 ebab0899ea..8f62a1f16a 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 1c2b6d3b5f..dd1e0c4c36 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 ec0a24c200..685d178182 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 6b632984fb..be7101a188 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 10725da1b6..3354aab303 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 fac14cef0d..1c57972c31 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 e133a49fe7..c0844d2c06 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 84389e3ed7..b5fa843f20 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 40ee5d0832..2d3ff53beb 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 64886f608d..99345bc0ac 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 4f96b1e86b..a9006714e3 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 15df4a577d..54dddc6a19 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 5924a10d7a..6e0e8aa345 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 4b09680ad9..3889670606 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 c8c3e83dc6..f5f30af716 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 594aa29e12..703f86ab24 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 e4d8f36f6c..a1ab8e3a1a 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