diff options
author | Josh Spicer <joshspicer@github.com> | 2022-07-14 21:12:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-14 21:12:11 +0300 |
commit | 01b46faa2dd7d9bd4f453b78f49457f2ffc67d3c (patch) | |
tree | 94cbf1eb77f763af807d34e168777c37dbc2668c | |
parent | 7f551f8c2f1129d6485088196bfeb28ff5ee3230 (diff) |
smart auto-install multiple versions for `node` (#56)
* node
* fix comment (no-ci)
* Apply suggestions from code review
Co-authored-by: Samruddhi Khandale <skhandale@microsoft.com>
* update test scenario
* remove minor for node 18
* update scenarios to object notation
* add shabang
* only set default node once
Co-authored-by: Samruddhi Khandale <skhandale@microsoft.com>
-rw-r--r-- | .github/workflows/test-pr-temp-tweak.yml | 15 | ||||
-rw-r--r-- | .github/workflows/test-pr.yaml | 2 | ||||
-rw-r--r-- | src/node/devcontainer-feature.json | 6 | ||||
-rw-r--r-- | src/node/install.sh | 25 | ||||
-rw-r--r-- | test-scenarios/install_additional_node.sh | 17 | ||||
-rw-r--r-- | test-scenarios/scenarios.json | 9 |
6 files changed, 67 insertions, 7 deletions
diff --git a/.github/workflows/test-pr-temp-tweak.yml b/.github/workflows/test-pr-temp-tweak.yml new file mode 100644 index 0000000..3f3dbe9 --- /dev/null +++ b/.github/workflows/test-pr-temp-tweak.yml @@ -0,0 +1,15 @@ +name: "test" +on: + pull_request: + paths-ignore: + - ./**/oryx/** + - ./**/java/** + - ./**/dotnet/** + - ./**/php/** + - ./**/node/** + +jobs: + test: + runs-on: ubuntu-latest + steps: + - run: 'echo "No build required ; Temporary tweak for merging the PRs until branch protection rules are updated"' diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index 86b492d..46334d7 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -39,7 +39,7 @@ jobs: terraform: ./**/terraform/** test: - needs: detect-changes + needs: [detect-changes] runs-on: ubuntu-latest continue-on-error: true strategy: diff --git a/src/node/devcontainer-feature.json b/src/node/devcontainer-feature.json index ebce21b..52715fd 100644 --- a/src/node/devcontainer-feature.json +++ b/src/node/devcontainer-feature.json @@ -34,9 +34,5 @@ "NVM_DIR": "/usr/local/share/nvm", "NVM_SYMLINK_CURRENT": "true", "PATH": "${NVM_DIR}/current/bin:${PATH}" - }, - "install": { - "app": "", - "file": "install.sh" } -}
\ No newline at end of file +} diff --git a/src/node/install.sh b/src/node/install.sh index b846007..7169919 100644 --- a/src/node/install.sh +++ b/src/node/install.sh @@ -11,6 +11,10 @@ export NODE_VERSION=${VERSION:-"lts"} export NVM_DIR=${NVM_INSTALL_PATH:-"/usr/local/share/nvm"} INSTALL_TOOLS_FOR_NODE_GYP="${INSTALL_TOOLS_FOR_NODE_GYP:-true}" +# Comma-separated list of node versions to be installed (with nvm) +# alongside NODE_VERSION, but not set as default. +ADDITIONAL_VERSIONS=${ADDITIONAL_VERSIONS:-""} + USERNAME=${USERNAME:-"automatic"} UPDATE_RC=${UPDATE_RC:-"true"} @@ -133,7 +137,7 @@ su ${USERNAME} -c "$(cat << EOF if [ "${NODE_VERSION}" != "" ]; then nvm alias default ${NODE_VERSION} fi - nvm clear-cache + nvm clear-cache EOF )" 2>&1 # Update rc files @@ -146,6 +150,25 @@ EOF )" fi +# Additional node versions to be installed but not be set as default. +if [ ! -z "${ADDITIONAL_VERSIONS}" ]; then + + OLDIFS=$IFS + IFS="," + read -a additional_versions <<< "$ADDITIONAL_VERSIONS" + for ver in "${additional_versions[@]}"; do + su ${USERNAME} -c ". $NVM_DIR/nvm.sh && nvm install ${ver}" + su ${USERNAME} -c ". $NVM_DIR/nvm.sh && nvm clear-cache" + # Reset the NODE_VERSION as the default version on the path. + done + + # Ensure $NODE_VERSION is on the $PATH + if [ "${NODE_VERSION}" != "" ]; then + su ${USERNAME} -c ". $NVM_DIR/nvm.sh && nvm use default" + fi + IFS=$OLDIFS +fi + # If enabled, verify "python3", "make", "gcc", "g++" commands are available so node-gyp works - https://github.com/nodejs/node-gyp if [ "${INSTALL_TOOLS_FOR_NODE_GYP}" = "true" ]; then echo "Verifying node-gyp OS requirements..." diff --git a/test-scenarios/install_additional_node.sh b/test-scenarios/install_additional_node.sh new file mode 100644 index 0000000..83dae86 --- /dev/null +++ b/test-scenarios/install_additional_node.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# 'latest' is some version of node 18 for a while. +check "version_on_path" node -v | grep 18 + +check "v18_installed" ls -1 /usr/local/share/nvm/versions/node | grep 18 +check "v14_installed" ls -1 /usr/local/share/nvm/versions/node | grep 14.19.3 +check "v17_installed" ls -1 /usr/local/share/nvm/versions/node | grep 17.9.1 + + +# Report result +reportResults diff --git a/test-scenarios/scenarios.json b/test-scenarios/scenarios.json index 5f594df..2c17057 100644 --- a/test-scenarios/scenarios.json +++ b/test-scenarios/scenarios.json @@ -12,6 +12,15 @@ } } }, + "install_additional_node": { + "image": "debian:11", + "features": { + "node": { + "version": "latest", + "additional_versions": "v17.9.1,v14.19.3" + } + } + }, "install_additional_python": { "image": "ubuntu:focal", "features": { |