[Fix] `nvm_get_arch`: proper value for alpine linux
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Andrius Solopovas · committed by Jordan Harband · parent b64e547 · Browse files · 3 files·+139 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+139 added−3 removed
- tests:+94 added−0 removed
- other:+45 added−3 removed
Provenance
- Commit
ef7fc2f- Tree
21ea024- Author
Andrius Solopovas <andrius.solopovas@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
b64e547
3 files changed+139 added−3 removed
modified:.github/workflows/windows-npm.yml+41 added-3 removed
124 unmodified linesExpand all1251261271281291301311291301311322 unmodified lines1351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821834 unmodified lines124 unmodified linesExpand all with: distribution: ${{ matrix.wsl-distrib }} additional-packages: bash git curl ca-certificates wget - name: Retrieve nvm on WSL env: C: /usr/bin/gcc-8 CXX: /usr/bin/g++-8 run: | if [ -z "${{ matrix.method }}" ]; then curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash else2 unmodified lines . "$HOME/.nvm/nvm.sh" nvm install ${{ matrix.npm-node-version }} node -v
wsl_matrix_unofficial: name: 'WSL nvm install' defaults: run: shell: wsl-bash {0} runs-on: windows-latest env: WSLENV: NVM_INSTALL_GITHUB_REPO:NVM_INSTALL_VERSION:/p NVM_NODEJS_ORG_MIRROR: https://unofficial-builds.nodejs.org/download/release strategy: fail-fast: false matrix: wsl-distrib: - Alpine npm-node-version: - '--lts' - '21' - '18' - '16' - '14' - '12' - '11' - '10' method: - '' - 'script' steps: - uses: Vampire/setup-wsl@v2 with: distribution: ${{ matrix.wsl-distrib }} additional-packages: bash git curl ca-certificates wget - name: Retrieve nvm on WSL run: | if [ -z "${{ matrix.method }}" ]; then curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash else curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD="${{matrix.method}}" bash fi . "$HOME/.nvm/nvm.sh" NVM_NODEJS_ORG_MIRROR=${{ env.NVM_NODEJS_ORG_MIRROR }} nvm install ${{ matrix.npm-node-version }}
nvm_windows: name: 'tests, on windows' permissions: contents: none4 unmodified linesadded:test/fast/Unit tests/nvm_get_arch_unofficial+94 added
1+#!/bin/sh2+3+# Save the PATH as it was when the test started to restore it when it finishes4+ORIG_PATH="${PATH}"5+6+cleanup() {7+ # Restore the PATH as it was when the test started8+ export PATH="${ORIG_PATH}"9+ rm -rf "${TMP_DIR}"10+}11+12+die() {13+ cleanup14+ echo "$@"15+ exit 116+}17+18+. ../../../nvm.sh19+20+# Sets the PATH for these tests to include the symlinks to the mocked binaries21+export PATH=".:${PATH}"22+23+TMP_DIR=$(mktemp -d)24+CHROOT_WITH_ALPINE="$TMP_DIR/with_alpine"25+CHROOT_WITHOUT_ALPINE="$TMP_DIR/without_alpine"26+27+setup_chroot() {28+ chroot_dir=$129+30+ # Directories31+ mkdir -p "${chroot_dir}/etc"32+ mkdir -p "${chroot_dir}/bin"33+ mkdir -p "${chroot_dir}/usr/bin"34+ mkdir -p "${chroot_dir}/lib64"35+ mkdir -p "${chroot_dir}/dev"36+37+ # Files and binaries38+ cp ../../../nvm.sh "${chroot_dir}/"39+ cp /bin/sh /usr/bin/dirname "${chroot_dir}/bin/"40+ [ "${chroot_dir}" = "${CHROOT_WITH_ALPINE}" ] && touch "${chroot_dir}/etc/alpine-release"41+42+ # Libraries43+ for binary in /bin/sh /usr/bin/dirname; do44+ for lib in $(ldd $binary | awk '{print $3}' | grep "^/"); do45+ dir=$(dirname "${lib}")46+ mkdir -p "${chroot_dir}${dir}"47+ cp "${lib}" "${chroot_dir}${dir}/"48+ done49+ done50+51+ # Dynamic linker52+ cp /lib64/ld-linux-x86-64.so.2 "${chroot_dir}/lib64/"53+54+ # /dev/null55+ sudo mknod "${chroot_dir}/dev/null" c 1 356+}57+58+setup_chroot "${CHROOT_WITH_ALPINE}"59+setup_chroot "${CHROOT_WITHOUT_ALPINE}"60+61+# Run tests in chroot environments62+ARCH_WITH_ALPINE=$(sudo chroot "${CHROOT_WITH_ALPINE}" /bin/sh -c ". ./nvm.sh && nvm_get_arch")63+[ "${ARCH_WITH_ALPINE}" = "x64-musl" ] || die "Expected x64-musl for alpine environment but got ${ARCH_WITH_ALPINE}"64+65+ARCH_WITHOUT_ALPINE=$(sudo chroot "${CHROOT_WITHOUT_ALPINE}" /bin/sh -c ". ./nvm.sh && nvm_get_arch")66+[ "${ARCH_WITHOUT_ALPINE}" != "x64-musl" ] || die "Did not expect x64-musl for non-alpine environment"67+68+# Run tests for nvm ls-remote69+test_default_ls_remote() {70+ mock_response='N/A'71+ result=$(NVM_NODEJS_ORG_MIRROR='http://nonexistent-url' nvm ls-remote 18)72+ if [ "${result}" = "${mock_response}" ]; then73+ die "Test failed: Expected '${mock_response}' for but got '${result}'"74+ else75+ echo "Test passed"76+ fi77+}78+79+test_unofficial_mirror_ls_remote() {80+ mock_response='v18.18.0 (LTS: Hydrogen)'81+ result=$(NVM_NODEJS_ORG_MIRROR='https://unofficial-builds.nodejs.org/download/release' nvm ls-remote 18.18.0 | sed -e 's/^[[:space:]]*//')82+ result=$(echo "${result}" | sed 's/\x1b\[[0-9;]*m//g')83+84+ if [ "${result}" = "${mock_response}" ]; then85+ echo "Test passed"86+ else87+ die "Test failed: Expected '${mock_response}' but got '${result}'"88+ fi89+}90+91+test_default_ls_remote92+test_unofficial_mirror_ls_remote93+94+cleanupmodified:nvm.sh+4 added
1963 unmodified lines1964 NVM_ARCH=armv7l1965 HOST_ARCH=armv7l1966 fi1967 1968+ if [ -f "/etc/alpine-release" ]; then1969+ NVM_ARCH=x64-musl1970+ fi1971+1972 nvm_echo "${NVM_ARCH}"1973 }1974 1975 nvm_get_minor_version() {2456 unmodified lines