-
Notifications
You must be signed in to change notification settings - Fork 69
ci(NODE-5089): download node to local directory #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,13 @@ | ||
| #! /usr/bin/env bash | ||
|
|
||
| export PATH="/opt/mongodbtoolchain/v2/bin:$PATH" | ||
| NODE_BINDINGS_PATH="${PROJECT_DIRECTORY}/bindings/node" | ||
| NODE_ARTIFACTS_PATH="${NODE_BINDINGS_PATH}/node-artifacts" | ||
| export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm" | ||
|
|
||
| NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts" | ||
| if [[ "$OS" == "Windows_NT" ]]; then | ||
| NVM_HOME=$(cygpath -w "$NVM_DIR") | ||
| export NVM_HOME | ||
| NVM_SYMLINK=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin") | ||
| export NVM_SYMLINK | ||
| NVM_ARTIFACTS_PATH=$(cygpath -w "$NODE_ARTIFACTS_PATH/bin") | ||
| export NVM_ARTIFACTS_PATH | ||
| PATH=$(cygpath $NVM_SYMLINK):$(cygpath $NVM_HOME):$PATH | ||
| export PATH | ||
| echo "updated path on windows PATH=$PATH" | ||
| nvm use lts | ||
| else | ||
| [ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" | ||
| nvm use --lts | ||
| NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH") | ||
| fi | ||
|
|
||
| export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH" | ||
| hash -r | ||
|
|
||
| export NODE_OPTIONS="--trace-deprecation --trace-warnings" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,79 +1,108 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -o xtrace # Write all commands first to stderr | ||
| set -o errexit # Exit the script with error if any of the commands fail | ||
|
|
||
| NODE_BINDINGS_PATH="${PROJECT_DIRECTORY}/bindings/node" | ||
| NODE_ARTIFACTS_PATH="${NODE_BINDINGS_PATH}/node-artifacts" | ||
| NPM_CACHE_DIR="${NODE_ARTIFACTS_PATH}/npm" | ||
| NPM_TMP_DIR="${NODE_ARTIFACTS_PATH}/tmp" | ||
| BIN_DIR="$(pwd)/bin" | ||
|
|
||
| NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.9/nvm-noinstall.zip" | ||
| NVM_URL="https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh" | ||
|
|
||
| # this needs to be explicitly exported for the nvm install below | ||
| export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm" | ||
|
|
||
| # create node artifacts path if needed | ||
| mkdir -p "${NODE_ARTIFACTS_PATH}" | ||
| mkdir -p "${NPM_CACHE_DIR}" | ||
| mkdir -p "${NPM_TMP_DIR}" | ||
| mkdir -p "${BIN_DIR}" | ||
| NODE_LTS_NAME=${NODE_LTS_NAME:-fermium} | ||
| NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts" | ||
| if [[ "$OS" = "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH"); fi | ||
|
|
||
| CURL_FLAGS=( | ||
| --fail # Exit code 1 if request fails | ||
| --compressed # Request a compressed response should keep fetching fast | ||
| --location # Follow a redirect | ||
| --retry 8 # Retry HTTP 408, 429, 500, 502, 503 or 504, 8 times | ||
| --silent # Do not print a progress bar | ||
| --show-error # Despite the silent flag still print out errors | ||
| --max-time 900 # 900 seconds is 15 minutes, evergreen times out at 20 | ||
| --continue-at - # If a download is interrupted it can figure out where to resume | ||
| ) | ||
|
|
||
| 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 | ||
| curl "${CURL_FLAGS[@]}" "https://nodejs.org/dist/index.tab" --output node_index.tab | ||
|
|
||
| while IFS=$'\t' read -r -a row; do | ||
| node_index_version="${row[0]}" | ||
| node_index_date="${row[1]}" | ||
| node_index_lts="${row[9]}" | ||
| [[ "$node_index_version" = "version" ]] && continue # skip tsv header | ||
| [[ "$NODE_LTS_NAME" = "latest" ]] && break # first line is latest | ||
| [[ "$NODE_LTS_NAME" = "$node_index_lts" ]] && break # case insensitive compare | ||
| done < node_index.tab | ||
|
|
||
| if [[ "$OS" = "Windows_NT" ]]; then | ||
| operating_system="win" | ||
| elif [[ $(uname) = "darwin" ]]; then | ||
| operating_system="darwin" | ||
| elif [[ $(uname) = "linux" ]]; then | ||
| operating_system="linux" | ||
| else | ||
| echo "Unable to determine operating system: $operating_system" | ||
| exit 1 | ||
| fi | ||
|
|
||
| export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm" | ||
| mkdir -p "${NVM_DIR}" | ||
| architecture=$(uname -m) | ||
| if [[ $architecture = "x86_64" ]]; then | ||
| architecture="x64" | ||
| elif [[ $architecture = "arm64" ]]; then | ||
| architecture="arm64" | ||
| elif [[ $architecture = "aarch64" ]]; then | ||
| architecture="arm64" | ||
| elif [[ $architecture == s390* ]]; then | ||
| architecture="s390x" | ||
| elif [[ $architecture == ppc* ]]; then | ||
| architecture="ppc64le" | ||
| else | ||
| echo "Unable to determine operating system: $architecture" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # install Node.js | ||
| if [ "$OS" == "Windows_NT" ]; then | ||
| set +o xtrace | ||
| file_extension="tar.gz" | ||
| if [[ "$OS" = "Windows_NT" ]]; then file_extension="zip"; fi | ||
|
|
||
| export NVM_HOME=`cygpath -w "$NVM_DIR"` | ||
| export NVM_SYMLINK=`cygpath -w "$NODE_ARTIFACTS_PATH/bin"` | ||
| export PATH=`cygpath $NVM_SYMLINK`:`cygpath $NVM_HOME`:$PATH | ||
| node_directory="node-${node_index_version}-${operating_system}-${architecture}" | ||
| node_archive="${node_directory}.${file_extension}" | ||
| node_archive_path="$NODE_ARTIFACTS_PATH/${node_archive}" | ||
| node_download_url="https://nodejs.org/dist/${node_index_version}/${node_archive}" | ||
|
|
||
| # download and install nvm | ||
| curl -L $NVM_WINDOWS_URL -o nvm.zip | ||
| unzip -d $NVM_DIR nvm.zip | ||
| rm nvm.zip | ||
| echo "Node.js ${node_index_version} for ${operating_system}-${architecture} released on ${node_index_date}" | ||
|
|
||
| chmod 777 $NVM_DIR | ||
| chmod -R a+rx $NVM_DIR | ||
| set -o xtrace | ||
|
|
||
| cat <<EOT > $NVM_DIR/settings.txt | ||
| root: $NVM_HOME | ||
| path: $NVM_SYMLINK | ||
| EOT | ||
| curl "${CURL_FLAGS[@]}" "${node_download_url}" --output "$node_archive_path" | ||
|
|
||
| echo "Running: nvm install lts" | ||
| nvm install lts | ||
| echo "Running: nvm use lts" | ||
| nvm use lts | ||
| echo "Running: npm install -g npm@8.3.1" | ||
| npm install -g npm@8.3.1 # https://github.com/npm/cli/issues/4341 | ||
| set -o xtrace | ||
| if [[ "$file_extension" = "zip" ]]; then | ||
| unzip -q "$node_archive_path" -d "${NODE_ARTIFACTS_PATH}" | ||
| mkdir -p "${NODE_ARTIFACTS_PATH}/nodejs" | ||
| # Windows "bins" are at the top level | ||
| mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs/bin" | ||
| # Need to add executable flag ourselves | ||
| chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/node.exe" | ||
| chmod +x "${NODE_ARTIFACTS_PATH}/nodejs/bin/npm" | ||
| else | ||
| set +o xtrace | ||
| tar -xf "$node_archive_path" -C "${NODE_ARTIFACTS_PATH}" | ||
| mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs" | ||
| fi | ||
|
|
||
| echo " Downloading nvm" | ||
| curl -o- $NVM_URL | bash | ||
| [ -s "${NVM_DIR}/nvm.sh" ] && source "${NVM_DIR}/nvm.sh" | ||
| export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH" | ||
| hash -r | ||
|
|
||
| echo "Running: nvm install --lts --latest-npm" | ||
| nvm install --lts --latest-npm | ||
| echo "Running: nvm use --lts" | ||
| nvm use --lts | ||
| # Set npm -g prefix to our local artifacts directory | ||
| cat <<EOT > .npmrc | ||
| prefix=$NODE_ARTIFACTS_PATH/npm_global | ||
| EOT | ||
|
|
||
| set -o xtrace | ||
| if [[ $operating_system != "win" ]]; then | ||
| # Update npm to latest when we can | ||
| npm install --global npm@latest | ||
| hash -r | ||
| fi | ||
|
|
||
| # setup npm cache in a local directory | ||
| cat <<EOT > .npmrc | ||
| devdir=${NPM_CACHE_DIR}/.node-gyp | ||
| init-module=${NPM_CACHE_DIR}/.npm-init.js | ||
| cache=${NPM_CACHE_DIR} | ||
| tmp=${NPM_TMP_DIR} | ||
| EOT | ||
| echo "npm version: $(npm -v)" | ||
|
|
||
| # install node dependencies | ||
| npm install | ||
| npm install "${NPM_OPTIONS}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.