Skip to content

Commit b79aec5

Browse files
committed
chore(NODE-5845): migrate node download script to drivers-tools
1 parent c35b125 commit b79aec5

File tree

4 files changed

+56
-123
lines changed

4 files changed

+56
-123
lines changed

.evergreen/config.yml

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,13 @@ functions:
1919
- command: git.get_project
2020
params:
2121
directory: src
22-
- command: shell.exec
22+
- command: subprocess.exec
2323
params:
2424
working_dir: src
25-
script: |
26-
# Get the current unique version of this checkout
27-
if [ "${is_patch}" = "true" ]; then
28-
CURRENT_VERSION=$(git describe)-patch-${version_id}
29-
else
30-
CURRENT_VERSION=latest
31-
fi
32-
export PROJECT_DIRECTORY="$(pwd)"
33-
# Python has cygwin path problems on Windows. Detect prospective mongo-orchestration home directory
34-
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
35-
export PROJECT_DIRECTORY=$(cygpath -m $PROJECT_DIRECTORY)
36-
fi
37-
cat <<EOT > expansion.yml
38-
CURRENT_VERSION: "$CURRENT_VERSION"
39-
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
40-
PREPARE_SHELL: |
41-
set -o errexit
42-
set -o xtrace
43-
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
44-
export PROJECT="${project}"
45-
EOT
46-
# See what we've done
47-
cat expansion.yml
25+
binary: bash
26+
add_expansions_to_env: true
27+
args:
28+
- '.evergreen/prepare-shell.sh'
4829
- command: expansions.update
4930
params:
5031
file: src/expansion.yml

.evergreen/install-dependencies.sh

Lines changed: 7 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,16 @@
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:-14}
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:-14}
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_major_version" ]] && break # case insensitive compare
43-
done < node_index.tab
44-
45-
if [[ "$OS" = "Windows_NT" ]]; then
46-
operating_system="win"
47-
elif [[ $(uname) = "darwin" ]]; then
48-
operating_system="darwin"
49-
elif [[ $(uname) = "linux" ]]; then
50-
operating_system="linux"
51-
else
52-
echo "Unable to determine operating system: $operating_system"
53-
exit 1
54-
fi
55-
56-
architecture=$(uname -m)
57-
if [[ $architecture = "x86_64" ]]; then
58-
architecture="x64"
59-
elif [[ $architecture = "arm64" ]]; then
60-
architecture="arm64"
61-
elif [[ $architecture = "aarch64" ]]; then
62-
architecture="arm64"
63-
elif [[ $architecture == s390* ]]; then
64-
architecture="s390x"
65-
elif [[ $architecture == ppc* ]]; then
66-
architecture="ppc64le"
67-
else
68-
echo "Unable to determine operating system: $architecture"
69-
exit 1
70-
fi
71-
72-
file_extension="tar.gz"
73-
if [[ "$OS" = "Windows_NT" ]]; then file_extension="zip"; fi
74-
75-
node_directory="node-${node_index_version}-${operating_system}-${architecture}"
76-
node_archive="${node_directory}.${file_extension}"
77-
node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}"
78-
node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}"
79-
80-
echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}"
81-
82-
set -o xtrace
83-
84-
curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path"
85-
86-
if [[ "$file_extension" = "zip" ]]; then
87-
unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}"
88-
mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs"
89-
# Windows "bins" are at the top level
90-
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin"
91-
# Need to add executable flag ourselves
92-
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe"
93-
chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm"
94-
else
95-
tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}"
96-
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
97-
fi
98-
99-
if [[ $operating_system != "win" ]]; then
100-
npm install --global npm@$NPM_VERSION
101-
hash -r
102-
fi
103-
104-
echo "npm location: $(which npm)"
105-
echo "npm version: $(npm -v)"
13+
source ./.drivers-tools/.evergreen/install-node.sh
10614

10715
npm install --build-from-source
10816
ldd build/*/kerberos.node || true

.evergreen/prepare-shell.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /usr/bin/env bash
2+
3+
# Only set errexit and xtrace if shell is NOT interactive
4+
[[ $- == *i* ]] || set -o xtrace
5+
[[ $- == *i* ]] || set -o errexit
6+
7+
export PROJECT_DIRECTORY="$(pwd)"
8+
export DRIVERS_TOOLS="$PROJECT_DIRECTORY/.drivers-tools"
9+
10+
if [ ! -d "$DRIVERS_TOOLS" ]; then
11+
# Only clone driver tools if it does not exist
12+
git clone --depth=1 "https://github.com/mongodb-labs/drivers-evergreen-tools.git" "${DRIVERS_TOOLS}"
13+
fi
14+
15+
echo "installed DRIVERS_TOOLS from commit $(git -C "${DRIVERS_TOOLS}" rev-parse HEAD)"
16+
17+
18+
# Get the current unique version of this checkout
19+
if [ "${is_patch}" = "true" ]; then
20+
CURRENT_VERSION=$(git describe)-patch-${version_id}
21+
else
22+
CURRENT_VERSION=latest
23+
fi
24+
25+
# Python has cygwin path problems on Windows. Detect prospective mongo-orchestration home directory
26+
if [ "Windows_NT" = "$OS" ]; then # Magic variable in cygwin
27+
export PROJECT_DIRECTORY=$(cygpath -m "$PROJECT_DIRECTORY")
28+
fi
29+
30+
cat <<EOT > expansion.yml
31+
CURRENT_VERSION: "$CURRENT_VERSION"
32+
PROJECT_DIRECTORY: "$PROJECT_DIRECTORY"
33+
PREPARE_SHELL: |
34+
set -o errexit
35+
set -o xtrace
36+
export PROJECT_DIRECTORY="$PROJECT_DIRECTORY"
37+
export PROJECT="${project}"
38+
EOT
39+
40+
# See what we've done
41+
cat expansion.yml

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ bindings
2424
.npmrc
2525

2626
*.tgz
27+
28+
expansion.yml
29+
.drivers-tools/

0 commit comments

Comments
 (0)