Skip to content
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

ci(NODE-5329): install npm to node_artifacts directory #581

Merged
merged 5 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .evergreen/init-node-and-npm-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /usr/bin/env bash
##
## This script add the location of `npm` and `node` to the path.
## This is necessary because evergreen uses separate bash scripts for
## different functions in a given CI run but doesn't persist the environment
## across them. So we manually invoke this script everywhere we need
## access to `npm`, `node`, or need to install something globally from
## npm.

NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
if [[ "$OS" == "Windows_NT" ]]; then
NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH")
fi

export NODE_ARTIFACTS_PATH
# npm uses this environment variable to determine where to install global packages
export npm_global_prefix=$NODE_ARTIFACTS_PATH/npm_global
export PATH="$npm_global_prefix/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
hash -r

export NODE_OPTIONS="--trace-deprecation --trace-warnings"
13 changes: 0 additions & 13 deletions .evergreen/init-nvm.sh

This file was deleted.

16 changes: 6 additions & 10 deletions .evergreen/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -o errexit # Exit the script with error if any of the commands fail

NODE_LTS_VERSION=${NODE_LTS_VERSION:-14}
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY:-$(pwd)}/node-artifacts"
if [[ "$OS" = "Windows_NT" ]]; then NODE_ARTIFACTS_PATH=$(cygpath --unix "$NODE_ARTIFACTS_PATH"); fi

source "${PROJECT_DIRECTORY}/.evergreen/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
baileympearson marked this conversation as resolved.
Show resolved Hide resolved

CURL_FLAGS=(
--fail # Exit code 1 if request fails
Expand Down Expand Up @@ -90,20 +93,13 @@ else
mv "${NODE_ARTIFACTS_PATH}/${node_directory}" "${NODE_ARTIFACTS_PATH}/nodejs"
fi

export PATH="$NODE_ARTIFACTS_PATH/npm_global/bin:$NODE_ARTIFACTS_PATH/nodejs/bin:$PATH"
hash -r

# Set npm -g prefix to our local artifacts directory
cat <<EOT > .npmrc
prefix=$NODE_ARTIFACTS_PATH/npm_global
EOT

if [[ $operating_system != "win" ]]; then
# Update npm to latest when we can
npm install --global npm@latest
hash -r
fi

echo "npm location: $(which npm)"
echo "npm version: $(npm -v)"

npm install "${NPM_OPTIONS}"
2 changes: 1 addition & 1 deletion .evergreen/run-bundling-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env bash

source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"

set -o xtrace
set -o errexit
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-checks.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -o errexit # Exit the script with error if any of the commands fail

source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"

npm run check:lint
2 changes: 1 addition & 1 deletion .evergreen/run-eslint-plugin-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -o errexit

source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"

cd etc/eslint/no-bigint-usage
npm install
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"

case $1 in
"node")
Expand Down
2 changes: 1 addition & 1 deletion .evergreen/run-typescript.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -o errexit # Exit the script with error if any of the commands fail

source "${PROJECT_DIRECTORY}/.evergreen/init-nvm.sh"
source "${PROJECT_DIRECTORY}/.evergreen/init-node-and-npm-env.sh"

set -o xtrace

Expand Down