Skip to content

Commit 7f5b334

Browse files
ci(NODE-5334): install npm to node_artifacts directory in CI (#3709)
1 parent e13038d commit 7f5b334

24 files changed

+48
-48
lines changed

.evergreen/init-node-and-npm-env.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/env bash
2+
##
3+
## This script add the location of `npm` and `node` to the path.
4+
## This is necessary because evergreen uses separate bash scripts for
5+
## different functions in a given CI run but doesn't persist the environment
6+
## across them. So we manually invoke this script everywhere we need
7+
## access to `npm`, `node`, or need to install something globally from
8+
## npm.
9+
10+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
11+
if [[ "$OS" == "Windows_NT" ]]; then
12+
NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH")
13+
fi
14+
15+
export NODE_ARTIFACTS_PATH
16+
# npm uses this environment variable to determine where to install global packages
17+
export npm_global_prefix=$NODE_ARTIFACTS_PATH/npm_global
18+
export PATH="$npm_global_prefix/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
19+
hash -r
20+
21+
export NODE_OPTIONS="--trace-deprecation --trace-warnings"

.evergreen/init-nvm.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

.evergreen/install-dependencies.sh

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
set -o errexit # Exit the script with error if any of the commands fail
33

44
NODE_LTS_VERSION=${NODE_LTS_VERSION:-12}
5-
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts"
6-
if [[ "$OS" = "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH"); fi
5+
6+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
7+
8+
if [[ -z "${npm_global_prefix}" ]]; then echo "npm_global_prefix is unset" && exit 1; fi
9+
if [[ -z "${NODE_ARTIFACTS_PATH}" ]]; then echo "NODE_ARTIFACTS_PATH is unset" && exit 1; fi
710

811
CURL_FLAGS=(
912
--fail # Exit code 1 if request fails
@@ -90,25 +93,14 @@ else
9093
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
9194
fi
9295

93-
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
94-
hash -r
95-
96-
# Set npm -g prefix to our local artifacts directory
97-
cat <<EOT > .npmrc
98-
prefix=$NODE_ARTIFACTS_PATH/npm_global
99-
EOT
100-
10196
# Cannot upgrade npm version for node 12
10297
if [[ $operating_system != "win" ]] && [[ $NODE_LTS_VERSION != 12 ]]; then
10398
# Update npm to latest when we can
10499
npm install --global npm@latest
105100
hash -r
106-
elif [[ $NODE_LTS_VERSION == 12 ]]; then
107-
# Node.js 12 can run up to npm v8
108-
npm install --global npm@8
109-
hash -r
110101
fi
111102

103+
echo "npm location: $(which npm)"
112104
echo "npm version: $(npm -v)"
113105

114106
npm install "${NPM_OPTIONS}"

.evergreen/run-atlas-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -o errexit # Exit the script with error if any of the commands fail
44

5-
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
5+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
66

77
set -o xtrace
88

.evergreen/run-benchmarks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/bash
22

3-
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
3+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
44

55
export MONGODB_URI=$MONGODB_URI
66

.evergreen/run-bson-ext-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
3+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
44

55
set -o xtrace # Write all commands first to stderr
66
set -o errexit # Exit the script with error if any of the commands fail

.evergreen/run-custom-csfle-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export CSFLE_KMS_PROVIDERS=${CSFLE_KMS_PROVIDERS}
1212
export CRYPT_SHARED_LIB_PATH=${CRYPT_SHARED_LIB_PATH}
1313
echo "csfle CRYPT_SHARED_LIB_PATH: $CRYPT_SHARED_LIB_PATH"
1414

15-
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
15+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
1616

1717
set -o xtrace # Write all commands first to stderr
1818
set -o errexit # Exit the script with error if any of the commands fail

.evergreen/run-data-lake-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -o errexit # Exit the script with error if any of the commands fail
44

5-
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
5+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
66

77
echo "$MONGODB_URI"
88
npm run check:adl

.evergreen/run-kerberos-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -o errexit # Exit the script with error if any of the commands fail
44

5-
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
5+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
66

77
# set up keytab
88
mkdir -p "$(pwd)/.evergreen"

.evergreen/run-lambda-aws-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ MONGODB_URI=${MONGODB_URI:-}
88
set +x
99

1010
# load node.js environment
11-
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
11+
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
1212

1313
# the default connection string, may be overridden by the environment script
1414
export MONGODB_URI="mongodb://localhost:27017/aws"

0 commit comments

Comments
 (0)