Skip to content

Commit 24c6a9c

Browse files
authored
ci(NODE-5087): download node to local directory (#566)
1 parent 800f7cd commit 24c6a9c

File tree

8 files changed

+134
-112
lines changed

8 files changed

+134
-112
lines changed

.evergreen/config.yml

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,35 @@ functions:
2929
- command: expansions.update
3030
params:
3131
file: src/expansion.yml
32+
3233
install dependencies:
33-
- command: shell.exec
34+
- command: subprocess.exec
3435
type: setup
3536
params:
3637
working_dir: src
37-
script: |
38-
${PREPARE_SHELL}
39-
echo "NODE_VERSION=${NODE_VERSION}"
40-
NODE_VERSION=${NODE_VERSION} ${PROJECT_DIRECTORY}/.evergreen/install-dependencies.sh
38+
binary: bash
39+
add_expansions_to_env: true
40+
args:
41+
- .evergreen/install-dependencies.sh
42+
4143
run tests:
4244
- command: shell.exec
4345
type: test
4446
params:
4547
working_dir: src
4648
script: |
4749
${PREPARE_SHELL}
48-
echo "NODE_VERSION=${NODE_VERSION} NO_BIGINT=${NO_BIGINT} TEST_TARGET=${TEST_TARGET}"
49-
NODE_VERSION=${NODE_VERSION} NO_BIGINT=${NO_BIGINT} ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh ${TEST_TARGET}
50+
echo "NO_BIGINT=${NO_BIGINT} TEST_TARGET=${TEST_TARGET}"
51+
NO_BIGINT=${NO_BIGINT} ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh ${TEST_TARGET}
52+
5053
run checks:
5154
- command: shell.exec
5255
type: test
5356
params:
5457
working_dir: src
5558
script: |
5659
${PREPARE_SHELL}
57-
echo "NODE_VERSION=${NODE_VERSION} TEST_TARGET=${TEST_TARGET}"
60+
echo "TEST_TARGET=${TEST_TARGET}"
5861
bash ${PROJECT_DIRECTORY}/.evergreen/run-checks.sh
5962
run typescript:
6063
- command: subprocess.exec
@@ -76,7 +79,6 @@ functions:
7679
working_dir: src
7780
timeout_secs: 60
7881
env:
79-
NODE_VERSION: ${NODE_VERSION}
8082
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
8183
binary: bash
8284
args:
@@ -88,7 +90,6 @@ functions:
8890
working_dir: src
8991
binary: bash
9092
env:
91-
NODE_VERSION: ${NODE_VERSION}
9293
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
9394
args:
9495
- .evergreen/run-bundling-test.sh
@@ -99,7 +100,7 @@ tasks:
99100
commands:
100101
- func: fetch source
101102
vars:
102-
NODE_MAJOR_VERSION: 14
103+
NODE_LTS_NAME: fermium
103104
- func: install dependencies
104105
- func: run tests
105106
vars:
@@ -109,7 +110,7 @@ tasks:
109110
commands:
110111
- func: fetch source
111112
vars:
112-
NODE_MAJOR_VERSION: 16
113+
NODE_LTS_NAME: gallium
113114
- func: install dependencies
114115
- func: run tests
115116
vars:
@@ -119,7 +120,7 @@ tasks:
119120
commands:
120121
- func: fetch source
121122
vars:
122-
NODE_MAJOR_VERSION: 18
123+
NODE_LTS_NAME: hydrogen
123124
- func: install dependencies
124125
- func: run tests
125126
vars:
@@ -129,7 +130,7 @@ tasks:
129130
commands:
130131
- func: fetch source
131132
vars:
132-
NODE_MAJOR_VERSION: latest
133+
NODE_LTS_NAME: latest
133134
- func: install dependencies
134135
- func: run tests
135136
vars:
@@ -139,7 +140,7 @@ tasks:
139140
commands:
140141
- func: fetch source
141142
vars:
142-
NODE_MAJOR_VERSION: 18
143+
NODE_LTS_NAME: hydrogen
143144
- func: install dependencies
144145
- func: run tests
145146
vars:
@@ -148,15 +149,15 @@ tasks:
148149
commands:
149150
- func: fetch source
150151
vars:
151-
NODE_MAJOR_VERSION: 18
152+
NODE_LTS_NAME: hydrogen
152153
- func: install dependencies
153154
- func: run bundling
154155
- name: no-bigint-web-tests
155156
tags: ["no-bigint", "web"]
156157
commands:
157158
- func: fetch source
158159
vars:
159-
NODE_MAJOR_VERSION: 18
160+
NODE_LTS_NAME: hydrogen
160161
- func: install dependencies
161162
- func: run tests
162163
vars:
@@ -168,14 +169,14 @@ tasks:
168169
commands:
169170
- func: fetch source
170171
vars:
171-
NODE_MAJOR_VERSION: 18
172+
NODE_LTS_NAME: hydrogen
172173
- func: install dependencies
173174
- func: run checks
174175
- name: check-typescript-oldest
175176
commands:
176177
- func: fetch source
177178
vars:
178-
NODE_MAJOR_VERSION: 18
179+
NODE_LTS_NAME: hydrogen
179180
- func: install dependencies
180181
- func: "run typescript"
181182
vars:
@@ -185,7 +186,7 @@ tasks:
185186
commands:
186187
- func: fetch source
187188
vars:
188-
NODE_MAJOR_VERSION: 18
189+
NODE_LTS_NAME: hydrogen
189190
- func: install dependencies
190191
- func: "run typescript"
191192
vars:
@@ -195,7 +196,7 @@ tasks:
195196
commands:
196197
- func: fetch source
197198
vars:
198-
NODE_MAJOR_VERSION: 18
199+
NODE_LTS_NAME: hydrogen
199200
- func: install dependencies
200201
- func: "run typescript"
201202
vars:
@@ -205,7 +206,7 @@ tasks:
205206
commands:
206207
- func: fetch source
207208
vars:
208-
NODE_MAJOR_VERSION: 18
209+
NODE_LTS_NAME: hydrogen
209210
- func: install dependencies
210211
- func: run eslint plugin tests
211212

.evergreen/init-nvm.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#! /usr/bin/env bash
22

33
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
4+
45
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
5-
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
6+
if [[ "$OS" == "Windows_NT" ]]; then
7+
NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH")
8+
fi
69

7-
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh"
10+
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
11+
hash -r
812

913
export NODE_OPTIONS="--trace-deprecation --trace-warnings"

.evergreen/install-dependencies.sh

Lines changed: 94 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,108 @@
1-
#!/bin/bash
2-
if [ -z "$NODE_VERSION" ]; then
3-
echo "NODE_VERSION environment variable must be specified"
1+
#!/usr/bin/env bash
2+
set -o errexit # Exit the script with error if any of the commands fail
3+
4+
NODE_LTS_NAME=${NODE_LTS_NAME:-fermium}
5+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts"
6+
if [[ "$OS" = "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH"); fi
7+
8+
CURL_FLAGS=(
9+
--fail # Exit code 1 if request fails
10+
--compressed # Request a compressed response should keep fetching fast
11+
--location # Follow a redirect
12+
--retry 8 # Retry HTTP 408, 429, 500, 502, 503 or 504, 8 times
13+
--silent # Do not print a progress bar
14+
--show-error # Despite the silent flag still print out errors
15+
--max-time 900 # 900 seconds is 15 minutes, evergreen times out at 20
16+
--continue-at - # If a download is interrupted it can figure out where to resume
17+
)
18+
19+
mkdir -p "$NODE_ARTIFACTS_PATH/npm_global"
20+
21+
# Comparisons are all case insensitive
22+
shopt -s nocasematch
23+
24+
# index.tab is a sorted tab separated values file with the following headers
25+
# 0 1 2 3 4 5 6 7 8 9 10
26+
# version date files npm v8 uv zlib openssl modules lts security
27+
curl "${CURL_FLAGS[@]}" "https://nodejs.org/dist/index.tab" --output node_index.tab
28+
29+
while IFS=$'\t' read -r -a row; do
30+
node_index_version="${row[0]}"
31+
node_index_date="${row[1]}"
32+
node_index_lts="${row[9]}"
33+
[[ "$node_index_version" = "version" ]] && continue # skip tsv header
34+
[[ "$NODE_LTS_NAME" = "latest" ]] && break # first line is latest
35+
[[ "$NODE_LTS_NAME" = "$node_index_lts" ]] && break # case insensitive compare
36+
done < node_index.tab
37+
38+
if [[ "$OS" = "Windows_NT" ]]; then
39+
operating_system="win"
40+
elif [[ $(uname) = "darwin" ]]; then
41+
operating_system="darwin"
42+
elif [[ $(uname) = "linux" ]]; then
43+
operating_system="linux"
44+
else
45+
echo "Unable to determine operating system: $operating_system"
446
exit 1
547
fi
648

7-
set -o errexit # Exit the script with error if any of the commands fail
49+
architecture=$(uname -m)
50+
if [[ $architecture = "x86_64" ]]; then
51+
architecture="x64"
52+
elif [[ $architecture = "arm64" ]]; then
53+
architecture="arm64"
54+
elif [[ $architecture = "aarch64" ]]; then
55+
architecture="arm64"
56+
elif [[ $architecture == s390* ]]; then
57+
architecture="s390x"
58+
elif [[ $architecture == ppc* ]]; then
59+
architecture="ppc64le"
60+
else
61+
echo "Unable to determine operating system: $architecture"
62+
exit 1
63+
fi
864

9-
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
10-
NPM_CACHE_DIR="${NODE_ARTIFACTS_PATH}/npm"
11-
NPM_TMP_DIR="${NODE_ARTIFACTS_PATH}/tmp"
12-
BIN_DIR="$(pwd)/bin"
13-
NVM_URL="https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh"
65+
file_extension="tar.gz"
66+
if [[ "$OS" = "Windows_NT" ]]; then file_extension="zip"; fi
1467

15-
# this needs to be explicitly exported for the nvm install below
16-
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
68+
node_directory="node-${node_index_version}-${operating_system}-${architecture}"
69+
node_archive="${node_directory}.${file_extension}"
70+
node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}"
71+
node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}"
1772

18-
# create node artifacts path if needed
19-
mkdir -p "${NODE_ARTIFACTS_PATH}"
20-
mkdir -p "${NPM_CACHE_DIR}"
21-
mkdir -p "${NPM_TMP_DIR}"
22-
mkdir -p "${BIN_DIR}"
23-
mkdir -p "${NVM_DIR}"
73+
echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"
2474

25-
# Add mongodb toolchain to path
26-
export PATH="${BIN_DIR}:${PATH}"
75+
set -o xtrace
2776

28-
# install Node.js
29-
echo "Installing Node ${NODE_LTS_NAME}"
77+
curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path"
3078

31-
set +o xtrace
79+
if [[ "$file_extension" = "zip" ]]; then
80+
unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}"
81+
mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs"
82+
# Windows "bins" are at the top level
83+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin"
84+
# Need to add executable flag ourselves
85+
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe"
86+
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm"
87+
else
88+
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
89+
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
90+
fi
3291

33-
echo " Downloading nvm"
34-
curl -o- $NVM_URL | bash
35-
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
92+
export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
93+
hash -r
3694

37-
echo "Running: nvm install --lts --latest-npm"
38-
nvm install --lts --latest-npm
39-
echo "Running: nvm install ${NODE_VERSION}"
40-
nvm install "${NODE_VERSION}"
41-
echo "Running: nvm use --lts"
42-
nvm use --lts
95+
# Set npm -g prefix to our local artifacts directory
96+
cat <<EOT > .npmrc
97+
prefix=$NODE_ARTIFACTS_PATH/npm_global
98+
EOT
4399

44-
set -o xtrace
100+
if [[ $operating_system != "win" ]]; then
101+
# Update npm to latest when we can
102+
npm install --global npm@latest
103+
hash -r
104+
fi
45105

46-
# install node dependencies
47-
npm install
106+
echo "npm version: $(npm -v)"
48107

49-
set +o xtrace
50-
echo "Running: nvm use ${NODE_VERSION}"
51-
nvm use "${NODE_VERSION}" # Switch to the node version we want to test against
52-
echo "Success: switched to node $(node -v)"
53-
set -o xtrace
108+
npm install "${NPM_OPTIONS}"

.evergreen/run-checks.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#!/bin/bash
22
set -o errexit # Exit the script with error if any of the commands fail
33

4-
export PROJECT_DIRECTORY="$(pwd)"
5-
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
6-
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
7-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
4+
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
85

96
npm run check:lint

.evergreen/run-eslint-plugin-test.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
if [ -z "$NODE_VERSION" ]; then
4-
echo "NODE_VERSION environment variable must be specified"
5-
exit 1
6-
fi
3+
set -o errexit
74

8-
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
9-
10-
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
11-
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
12-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
5+
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
136

147
cd etc/eslint/no-bigint-usage
158
npm install

.evergreen/run-tests.sh

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
#!/bin/bash
2-
if [ -z "$NODE_VERSION" ]; then
3-
echo "NODE_VERSION environment variable must be specified"
4-
exit 1
5-
fi
6-
7-
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
8-
9-
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
10-
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
11-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
1+
#!/usr/bin/env bash
122

3+
source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
134

145
case $1 in
156
"node")

0 commit comments

Comments
 (0)