Skip to content

Commit

Permalink
[Node] - nvm - fallback to previous version - code fix (#904)
Browse files Browse the repository at this point in the history
* [node] - nvm - added fallback to prev. version - if latest version tag released but binary not found

* bumped patch version
  • Loading branch information
gauravsaini04 authored Mar 12, 2024
1 parent 8af4ce3 commit 460684d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/node/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "node",
"version": "1.4.0",
"version": "1.4.1",
"name": "Node.js (via nvm), yarn and pnpm",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/node",
"description": "Installs Node.js, nvm, yarn, pnpm, and needed dependencies.",
Expand Down
7 changes: 5 additions & 2 deletions src/node/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,11 @@ set -e
umask 0002
# Do not update profile - we'll do this manually
export PROFILE=/dev/null
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh" | bash
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh" | bash || {
PREV_NVM_VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/\${PREV_NVM_VERSION}/install.sh" | bash
NVM_VERSION="\${PREV_NVM_VERSION}"
}
source "${NVM_DIR}/nvm.sh"
if [ "${NODE_VERSION}" != "" ]; then
nvm alias default "${NODE_VERSION}"
Expand Down
27 changes: 27 additions & 0 deletions test/node/nvm_test_fallback.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

set -e

trap 'echo "Error occurred at line $LINENO"; exit 1' ERR
source /usr/local/share/nvm/nvm.sh
#check nvm version
echo -e "\n✅ nvm version as installed by feature = v$(nvm --version)";
NVM_DIR="/usr/local/share/nvm"
NODE_VERSION="lts"
FAKE_NVM_VERSION="1.2.XYZ"
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/v${FAKE_NVM_VERSION}/install.sh" | bash || {
PREV_NVM_VERSION=$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
curl -so- "https://raw.githubusercontent.com/nvm-sh/nvm/${PREV_NVM_VERSION}/install.sh" | bash
NVM_VERSION="${PREV_NVM_VERSION}"
}

#check nvm version
echo -e "\n✅ nvm version as installed by test = v$(nvm --version)";

# Report result
reportResults
8 changes: 8 additions & 0 deletions test/node/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"nvm_test_fallback": {
"image": "debian:11",
"features": {
"node": {
"version": "lts"
}
}
},
"install_additional_node": {
"image": "debian:11",
"features": {
Expand Down

0 comments on commit 460684d

Please sign in to comment.