Skip to content

Commit c08fa56

Browse files
authored
chore(NODE-6401): migrate node download script to drivers-tools (#718)
1 parent 064ba91 commit c08fa56

14 files changed

+44
-132
lines changed

.evergreen/config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ functions:
2525
binary: bash
2626
add_expansions_to_env: true
2727
args:
28-
- .evergreen/setup-environment.sh
28+
- '.evergreen/prepare-shell.sh'
2929
- command: expansions.update
3030
params:
3131
file: src/expansion.yml
@@ -76,6 +76,7 @@ functions:
7676
params:
7777
working_dir: src
7878
timeout_secs: 60
79+
add_expansions_to_env: true
7980
env:
8081
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
8182
TS_VERSION: "${TS_VERSION}"
@@ -89,6 +90,7 @@ functions:
8990
params:
9091
working_dir: src
9192
timeout_secs: 60
93+
add_expansions_to_env: true
9294
env:
9395
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
9496
binary: bash
@@ -100,6 +102,7 @@ functions:
100102
params:
101103
working_dir: src
102104
binary: bash
105+
add_expansions_to_env: true
103106
env:
104107
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
105108
args:

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

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

.evergreen/install-dependencies.sh

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

4-
NODE_LTS_VERSION=${NODE_LTS_VERSION:-16}
4+
# allowed values:
5+
## a nodejs major version (i.e., 16)
6+
## 'latest'
7+
## a full nodejs version, in the format v<major>.<minor>.patch
8+
export NODE_LTS_VERSION=${NODE_LTS_VERSION:-16}
59
# npm version can be defined in the environment for cases where we need to install
610
# a version lower than latest to support EOL Node versions.
7-
NPM_VERSION=${NPM_VERSION:-latest}
11+
export NPM_VERSION=${NPM_VERSION:-latest}
812

9-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
10-
11-
if [[ -z "${npm_global_prefix}" ]]; then echo "npm_global_prefix is unset" && exit 1; fi
12-
if [[ -z "${NODE_ARTIFACTS_PATH}" ]]; then echo "NODE_ARTIFACTS_PATH is unset" && exit 1; fi
13-
14-
CURL_FLAGS=(
15-
--fail # Exit code 1 if request fails
16-
--compressed # Request a compressed response should keep fetching fast
17-
--location # Follow a redirect
18-
--retry 8 # Retry HTTP 408, 429, 500, 502, 503 or 504, 8 times
19-
--silent # Do not print a progress bar
20-
--show-error # Despite the silent flag still print out errors
21-
--max-time 900 # 900 seconds is 15 minutes, evergreen times out at 20
22-
--continue-at - # If a download is interrupted it can figure out where to resume
23-
)
24-
25-
mkdir -p "$NODE_ARTIFACTS_PATH/npm_global"
26-
27-
# Comparisons are all case insensitive
28-
shopt -s nocasematch
29-
30-
# index.tab is a sorted tab separated values file with the following headers
31-
# 0 1 2 3 4 5 6 7 8 9 10
32-
# version date files npm v8 uv zlib openssl modules lts security
33-
curl "${CURL_FLAGS[@]}" "https://nodejs.org/dist/index.tab" --output node_index.tab
34-
35-
while IFS=$'\t' read -r -a row; do
36-
node_index_version="${row[0]}"
37-
node_index_major_version=$(echo $node_index_version | sed -E 's/^v([0-9]+).*$/\1/')
38-
node_index_date="${row[1]}"
39-
node_index_lts="${row[9]}"
40-
[[ "$node_index_version" = "version" ]] && continue # skip tsv header
41-
[[ "$NODE_LTS_VERSION" = "latest" ]] && break # first line is latest
42-
[[ "$NODE_LTS_VERSION" = "$node_index_version" ]] && break # match full version if specified
43-
[[ "$NODE_LTS_VERSION" = "$node_index_major_version" ]] && break # case insensitive compare
44-
done < node_index.tab
45-
46-
if [[ "$OS" = "Windows_NT" ]]; then
47-
operating_system="win"
48-
elif [[ $(uname) = "darwin" ]]; then
49-
operating_system="darwin"
50-
elif [[ $(uname) = "linux" ]]; then
51-
operating_system="linux"
52-
else
53-
echo "Unable to determine operating system: $operating_system"
54-
exit 1
55-
fi
56-
57-
architecture=$(uname -m)
58-
if [[ $architecture = "x86_64" ]]; then
59-
architecture="x64"
60-
elif [[ $architecture = "arm64" ]]; then
61-
architecture="arm64"
62-
elif [[ $architecture = "aarch64" ]]; then
63-
architecture="arm64"
64-
elif [[ $architecture == s390* ]]; then
65-
architecture="s390x"
66-
elif [[ $architecture == ppc* ]]; then
67-
architecture="ppc64le"
68-
else
69-
echo "Unable to determine operating system: $architecture"
70-
exit 1
71-
fi
72-
73-
file_extension="tar.gz"
74-
if [[ "$OS" = "Windows_NT" ]]; then file_extension="zip"; fi
75-
76-
node_directory="node-${node_index_version}-${operating_system}-${architecture}"
77-
node_archive="${node_directory}.${file_extension}"
78-
node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}"
79-
node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}"
80-
81-
echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"
82-
83-
set -o xtrace
84-
85-
curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path"
86-
87-
if [[ "$file_extension" = "zip" ]]; then
88-
unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}"
89-
mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs"
90-
# Windows "bins" are at the top level
91-
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin"
92-
# Need to add executable flag ourselves
93-
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe"
94-
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm"
95-
else
96-
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
97-
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
98-
fi
99-
100-
if [[ $operating_system != "win" ]]; then
101-
npm install --global npm@$NPM_VERSION
102-
hash -r
103-
fi
104-
105-
echo "npm location: $(which npm)"
106-
echo "npm version: $(npm -v)"
13+
source $DRIVERS_TOOLS/.evergreen/install-node.sh
10714

10815
npm install "${NPM_OPTIONS}"
16+
17+
npm ls

.evergreen/setup-environment.sh renamed to .evergreen/prepare-shell.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
#! /usr/bin/env bash
22

3+
# Only set errexit and xtrace if shell is NOT interactive
4+
[[ $- == *i* ]] || set -o xtrace
5+
[[ $- == *i* ]] || set -o errexit
6+
7+
PROJECT_DIRECTORY="$(pwd)"
8+
DRIVERS_TOOLS=$(cd .. && echo "$(pwd)/drivers-tools")
9+
export PROJECT_DIRECTORY
10+
export DRIVERS_TOOLS
11+
12+
13+
if [ ! -d "$DRIVERS_TOOLS" ]; then
14+
# Only clone driver tools if it does not exist
15+
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
16+
fi
17+
18+
echo "installed DRIVERS_TOOLS from commit $(git -C "${DRIVERS_TOOLS}" rev-parse HEAD)"
19+
320
if [ -z "$NODE_LTS_VERSION" ]; then
421
echo "NODE_LTS_VERSION environment variable must be specified"
522
exit 1
@@ -11,17 +28,18 @@ if [ "${is_patch}" = "true" ]; then
1128
else
1229
CURRENT_VERSION=latest
1330
fi
14-
export PROJECT_DIRECTORY="$(pwd)"
1531

1632
cat <<EOT > expansion.yml
1733
CURRENT_VERSION: "$CURRENT_VERSION"
1834
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
1935
NODE_LTS_VERSION: "$NODE_LTS_VERSION"
36+
DRIVERS_TOOLS: "$DRIVERS_TOOLS"
2037
PREPARE_SHELL: |
2138
set -o errexit
2239
set -o xtrace
2340
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
2441
export NODE_LTS_VERSION="$NODE_LTS_VERSION"
42+
export DRIVERS_TOOLS="$DRIVERS_TOOLS"
2543
EOT
2644
# See what we've done
2745
cat expansion.yml

.evergreen/run-big-endian-test.sh

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

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

55
npx mocha test/s390x/big_endian.test.ts

.evergreen/run-bundling-test.sh

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

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

55
set -o xtrace
66
set -o errexit

.evergreen/run-checks.sh

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

4-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
4+
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
55

66
npm run check:lint

.evergreen/run-custom-benchmarks.sh

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

3-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
3+
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
44
set -o xtrace
55

66
npm run check:custom-bench

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

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

33
set -o errexit
44

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

77
cd etc/eslint/no-bigint-usage
88
npm install

.evergreen/run-granular-benchmarks.sh

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

3-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
3+
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
44
set -o xtrace
55
WARMUP=$WARMUP
66
ITERATIONS=$ITERATIONS

.evergreen/run-spec-benchmarks.sh

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

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

55
npm run check:spec-bench

.evergreen/run-tests.sh

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

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

55
case "${TEST_TARGET}" in
66
"node")

.evergreen/run-typescript.sh

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

4-
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"
4+
source $DRIVERS_TOOLS/.evergreen/init-node-and-npm-env.sh
55

66
set -o xtrace
77

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ docs/public
3434

3535
benchmarks.json
3636
customBenchmarkResults.json
37+
38+
expansion.yml
39+
.drivers-tools/

0 commit comments

Comments
 (0)