diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 5da91dc3..d6ef6376 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -499,7 +499,6 @@ functions: type: test params: binary: bash - include_expansions_in_env: [SKIP_NODE] args: [src/.evergreen/tests/test-install-binaries.sh] "run aws test": @@ -1386,8 +1385,6 @@ axes: - id: rhel7 display_name: "RHEL 7" run_on: rhel70-small - variables: - SKIP_NODE: 1 - id: rhel8-power8 display_name: "RHEL 8 (POWER8)" diff --git a/.evergreen/handle-paths.sh b/.evergreen/handle-paths.sh index dd42f8ec..2d245cb0 100755 --- a/.evergreen/handle-paths.sh +++ b/.evergreen/handle-paths.sh @@ -8,10 +8,16 @@ # SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) # . $SCRIPT_DIR/../handle-path.sh -set -o errexit # Exit the script with error if any of the commands fail +# Avoid overwriting caller's flags. +# shellcheck disable=SC2034 +set -o | grep -q '^errexit.*on$' && errexit_was_set=true || errexit_was_set=false +# shellcheck disable=SC2034 +set -o | grep -q '^nounset.*on$' && nounset_was_set=true || nounset_was_set=false -if [ -z "$SCRIPT_DIR" ]; then - echo "Please set $SCRIPT_DIR first" +set -eu + +if [ -z "${SCRIPT_DIR:-}" ]; then + echo "Please set SCRIPT_DIR first" exit 1 fi @@ -65,3 +71,7 @@ case "$PATH" in PATH="$PATH:$DRIVERS_TOOLS/.bin" ;; esac + +# Restore flags. +$errexit_was_set && set -e || set +e +$nounset_was_set && set -u || set +u diff --git a/.evergreen/init-node-and-npm-env.sh b/.evergreen/init-node-and-npm-env.sh index 68646612..a39e71e6 100755 --- a/.evergreen/init-node-and-npm-env.sh +++ b/.evergreen/init-node-and-npm-env.sh @@ -1,4 +1,5 @@ #! /usr/bin/env bash +# shellcheck shell=sh ## ## This script add the location of `npm` and `node` to the path. ## This is necessary because evergreen uses separate bash scripts for @@ -7,10 +8,12 @@ ## access to `npm`, `node`, or need to install something globally from ## npm. -SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) -. $SCRIPT_DIR/handle-paths.sh -NODE_ARTIFACTS_PATH="$SCRIPT_DIR/node-artifacts" -if [[ "${OS:-}" == "Windows_NT" ]]; then +# See https://stackoverflow.com/questions/35006457/choosing-between-0-and-bash-source/35006505#35006505 +# Why we need this syntax when sh is not aliased to bash (this script must be able to be called from sh) +# shellcheck disable=SC3028 +_SCRIPT_DIR=$(dirname ${BASH_SOURCE:-$0}) +NODE_ARTIFACTS_PATH="$_SCRIPT_DIR/node-artifacts" +if [ "${OS:-}" = "Windows_NT" ]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH") fi diff --git a/.evergreen/install-node.sh b/.evergreen/install-node.sh index 73cc9fbb..4840aea2 100755 --- a/.evergreen/install-node.sh +++ b/.evergreen/install-node.sh @@ -3,9 +3,13 @@ set -o errexit # Exit the script with error if any of the commands fail SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) . $SCRIPT_DIR/handle-paths.sh -pushd $SCRIPT_DIR -NODE_LTS_VERSION=${NODE_LTS_VERSION:-20} +DEFAULT_NODE_VERSION=20 +if grep -q "release 7" /etc/redhat-release 2> /dev/null; then + DEFAULT_NODE_VERSION=16 +fi +NODE_LTS_VERSION=${NODE_LTS_VERSION:-$DEFAULT_NODE_VERSION} + # If NODE_LTS_VERSION is numeric and less than 18, default to 9, if less than 20, default to 10. # Do not override if it is already set. if [[ "$NODE_LTS_VERSION" =~ ^[0-9]+$ && "$NODE_LTS_VERSION" -lt 18 ]]; then @@ -17,11 +21,32 @@ else fi export NPM_VERSION=${NPM_VERSION} -source "./init-node-and-npm-env.sh" +source "$SCRIPT_DIR/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 +function debug_output { + echo "node location: $(which node)" + echo "node version: $(node -v)" + echo "npm location: $(which npm)" + echo "npm version: $(npm -v)" + echo "Run 'source init-node-and-npm-env.sh' to handle environment setup." +} + +# Bail early if this version of node was already installed. +if grep -Fxq "$NODE_LTS_VERSION" $NODE_ARTIFACTS_PATH/node-version.txt 2> /dev/null; then + echo "Node $NODE_LTS_VERSION already installed!" + debug_output + exit 0 +fi + +# Ensure a clean directory. +rm -rf $NODE_ARTIFACTS_PATH +mkdir -p "$NODE_ARTIFACTS_PATH/npm_global" + +echo "Installing Node.js $NODE_LTS_VERSION..." + CURL_FLAGS=( --fail # Exit code 1 if request fails --compressed # Request a compressed response should keep fetching fast @@ -32,19 +57,16 @@ CURL_FLAGS=( --max-time 900 # 900 seconds is 15 minutes, evergreen times out at 20 ) -mkdir -p "$NODE_ARTIFACTS_PATH/npm_global" - # Comparisons are all case insensitive shopt -s nocasematch # index.tab is a sorted tab separated values file with the following headers # 0 1 2 3 4 5 6 7 8 9 10 # version date files npm v8 uv zlib openssl modules lts security -"$SCRIPT_DIR/retry-with-backoff.sh" curl "${CURL_FLAGS[@]}" "https://nodejs.org/dist/index.tab" --output node_index.tab +"$SCRIPT_DIR/retry-with-backoff.sh" curl "${CURL_FLAGS[@]}" "https://nodejs.org/dist/index.tab" --output node_index.tab > /dev/null 2>&1 while IFS=$'\t' read -r -a row; do node_index_version="${row[0]}" - echo $node_index_version >> "versions.txt" node_index_major_version=$(echo $node_index_version | sed -E 's/^v([0-9]+).*$/\1/') node_index_date="${row[1]}" [[ "$node_index_version" = "version" ]] && continue # skip tsv header @@ -93,13 +115,17 @@ node_shasum_url="https://nodejs.org/dist/${node_index_version}/SHASUMS256.txt" echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}" +"$SCRIPT_DIR/retry-with-backoff.sh" curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path" > /dev/null 2>&1 +"$SCRIPT_DIR/retry-with-backoff.sh" curl "${CURL_FLAGS[@]}" "${node_shasum_url}" --output "$node_shasum_path" > /dev/null 2>&1 + +# Remove extra entries from the SHASUMS256.txt file. Not every OS supports the --ignore-missing flag. +( + cd "$NODE_ARTIFACTS_PATH" + awk '{ if (system("[ -e \"" $2 "\" ]") == 0) print $0 }' SHASUMS256.txt > SHASUMS256.filtered.txt + sha256sum -c SHASUMS256.filtered.txt > /dev/null 2>&1 || sha256sum -c SHASUMS256.filtered.txt +) + if [[ "$file_extension" = "zip" ]]; then - if [[ -d "${NODE_ARTIFACTS_PATH}/nodejs/bin/${node_directory}" ]]; then - echo "Node.js already installed!" - else - "$SCRIPT_DIR/retry-with-backoff.sh" curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path" - "$SCRIPT_DIR/retry-with-backoff.sh" curl "${CURL_FLAGS[@]}" "${node_shasum_url}" --output "$node_shasum_path" - (cd "$NODE_ARTIFACTS_PATH" && sha256sum -c SHASUMS256.txt --ignore-missing) unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}" mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs" # Windows "bins" are at the top level @@ -107,28 +133,21 @@ if [[ "$file_extension" = "zip" ]]; then # Need to add executable flag ourselves chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe" chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm" - fi + chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npx" + chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npx.CMD" else - if [[ -d "${NODE_ARTIFACTS_PATH}/nodejs/${node_directory}" ]]; then - echo "Node.js already installed!" - else - "$SCRIPT_DIR/retry-with-backoff.sh" curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path" - "$SCRIPT_DIR/retry-with-backoff.sh" curl "${CURL_FLAGS[@]}" "${node_shasum_url}" --output "$node_shasum_path" - pushd $NODE_ARTIFACTS_PATH - sha256sum -c SHASUMS256.txt --ignore-missing - popd tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}" mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs" - fi fi +echo "$NODE_LTS_VERSION" > $NODE_ARTIFACTS_PATH/node-version.txt +echo "Installing Node.js $NODE_LTS_VERSION... done." if [[ $operating_system != "win" ]]; then # Update npm to latest when we can - npm install --global npm@$NPM_VERSION + echo "Installing npm $NPM_VERSION..." + npm install --silent --global npm@$NPM_VERSION hash -r + echo "Installing npm $NPM_VERSION... done." fi -echo "npm location: $(which npm)" -echo "npm version: $(npm -v)" - -popd +debug_output diff --git a/.evergreen/install-rust.sh b/.evergreen/install-rust.sh index aee8305d..51b2eadc 100755 --- a/.evergreen/install-rust.sh +++ b/.evergreen/install-rust.sh @@ -5,9 +5,9 @@ SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) . $SCRIPT_DIR/handle-paths.sh pushd $SCRIPT_DIR -export RUSTUP_HOME="${RUSTUP_HOME:-"${DRIVERS_TOOLS}/.rustup"}" -export CARGO_HOME="${CARGO_HOME:-"${DRIVERS_TOOLS}/.cargo"}" -export PATH="${CARGO_HOME}/bin:$PATH" +RUSTUP_HOME="${RUSTUP_HOME:-"${DRIVERS_TOOLS}/.rustup"}" +CARGO_HOME="${CARGO_HOME:-"${DRIVERS_TOOLS}/.cargo"}" +PATH="${CARGO_HOME}/bin:$PATH" # Make sure to use msvc toolchain rather than gnu, which is the default for cygwin if [ "Windows_NT" == "${OS:-}" ]; then @@ -30,4 +30,8 @@ echo "cargo version: $(cargo --version)" echo "rustc location: $(which rustc)" echo "rustc version: $(rustc --version)" +export RUSTUP_HOME +export CARGO_HOME +export PATH + popd diff --git a/.evergreen/tests/test-install-binaries.sh b/.evergreen/tests/test-install-binaries.sh index 35d9c60e..e80254da 100755 --- a/.evergreen/tests/test-install-binaries.sh +++ b/.evergreen/tests/test-install-binaries.sh @@ -6,11 +6,11 @@ SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) pushd $SCRIPT_DIR/.. -if [ -z "${SKIP_NODE:-}" ]; then - ./install-node.sh -fi +./install-node.sh +npx -y mongodb-runner --help -./install-rust.sh +source ./install-rust.sh +rustup install stable if [ ${OS:-} != "Windows_NT" ]; then # Add a suitable python3 to the path.