mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 14:21:50 +00:00
parent
a8c418558a
commit
c31a867c46
104
.github/workflows/nvm-install-test.yml
vendored
Normal file
104
.github/workflows/nvm-install-test.yml
vendored
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
name: 'Tests: nvm install with set -e'
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
ref:
|
||||||
|
description: 'git ref to use'
|
||||||
|
required: false
|
||||||
|
default: 'HEAD'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
matrix:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
matrix: ${{ steps.matrix.outputs.matrix }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- id: matrix
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.ref }}" ]; then
|
||||||
|
echo "matrix=\"[\"${{ github.event.inputs.ref }}\"]\"" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
TAGS="$((echo "HEAD" && git tag --sort=-v:refname --merged HEAD --format='%(refname:strip=2) %(creatordate:short)' | grep '^v' | while read tag date; do
|
||||||
|
if [ "$(uname)" == "Darwin" ]; then
|
||||||
|
timestamp=$(date -j -f "%Y-%m-%d" "$date" +%s)
|
||||||
|
threshold=$(date -j -v-4y +%s)
|
||||||
|
else
|
||||||
|
timestamp=$(date -d "$date" +%s)
|
||||||
|
threshold=$(date -d "4 years ago" +%s)
|
||||||
|
fi
|
||||||
|
if [ $timestamp -ge $threshold ]; then echo "$tag"; fi
|
||||||
|
done) | xargs)"
|
||||||
|
echo $TAGS
|
||||||
|
TAGS_JSON=$(printf "%s\n" $TAGS | jq -R . | jq -sc .)
|
||||||
|
echo "matrix=${TAGS_JSON}" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
test:
|
||||||
|
needs: [matrix]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: ${{ matrix.ref == 'v0.40.0' }} # https://github.com/nvm-sh/nvm/issues/3405
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
ref: ${{ fromJson(needs.matrix.outputs.matrix) }}
|
||||||
|
has-nvmrc:
|
||||||
|
- 'no nvmrc'
|
||||||
|
- 'nvmrc'
|
||||||
|
shell-level:
|
||||||
|
- 1 shlvl
|
||||||
|
- 2 shlvls
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: resolve HEAD to sha
|
||||||
|
run: |
|
||||||
|
if [ '${{ matrix.ref }}' = 'HEAD' ]; then
|
||||||
|
REF="$(git rev-parse HEAD)"
|
||||||
|
else
|
||||||
|
REF="${{ matrix.ref }}"
|
||||||
|
fi
|
||||||
|
echo "resolved ref: ${REF}"
|
||||||
|
echo "ref="$REF"" >> $GITHUB_ENV
|
||||||
|
- run: echo $- # which options are set
|
||||||
|
- run: echo node > .nvmrc
|
||||||
|
if: ${{ matrix.has-nvmrc == 'nvmrc' }}
|
||||||
|
- run: curl -I --compressed -v https://nodejs.org/dist/
|
||||||
|
- name: 'install nvm'
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
export NVM_INSTALL_VERSION="${ref}"
|
||||||
|
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${ref}/install.sh" | bash
|
||||||
|
- name: nvm --version
|
||||||
|
run: |
|
||||||
|
set +e
|
||||||
|
. $NVM_DIR/nvm.sh && nvm --version
|
||||||
|
- name: nvm install in 1 shell level, ${{ matrix.has-nvmrc }}
|
||||||
|
if: ${{ matrix.shell-level == '1 shlvl' }}
|
||||||
|
run: |
|
||||||
|
set -ex
|
||||||
|
. $NVM_DIR/nvm.sh
|
||||||
|
echo nvm.sh sourced
|
||||||
|
nvm --version
|
||||||
|
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
|
||||||
|
nvm install
|
||||||
|
fi
|
||||||
|
- name: nvm install in 2 shell levels, ${{ matrix.has-nvmrc }}
|
||||||
|
if: ${{ matrix.shell-level == '2 shlvls' }}
|
||||||
|
run: |
|
||||||
|
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
|
||||||
|
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version && nvm install"
|
||||||
|
else
|
||||||
|
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version"
|
||||||
|
fi
|
||||||
|
|
||||||
|
finisher:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [test]
|
||||||
|
steps:
|
||||||
|
- run: true
|
58
nvm.sh
58
nvm.sh
@ -4556,31 +4556,41 @@ nvm_supports_xz() {
|
|||||||
nvm_auto() {
|
nvm_auto() {
|
||||||
local NVM_MODE
|
local NVM_MODE
|
||||||
NVM_MODE="${1-}"
|
NVM_MODE="${1-}"
|
||||||
local VERSION
|
|
||||||
local NVM_CURRENT
|
case "${NVM_MODE}" in
|
||||||
if [ "_${NVM_MODE}" = '_install' ]; then
|
none) return 0 ;;
|
||||||
VERSION="$(nvm_alias default 2>/dev/null || nvm_echo)"
|
use | install)
|
||||||
if [ -n "${VERSION}" ] && ! [ "_${VERSION}" = '_N/A' ] && nvm_is_valid_version "${VERSION}"; then
|
local VERSION
|
||||||
nvm install "${VERSION}" >/dev/null
|
local NVM_CURRENT
|
||||||
elif nvm_rc_version >/dev/null 2>&1; then
|
NVM_CURRENT="$(nvm_ls_current)"
|
||||||
nvm install >/dev/null
|
if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then
|
||||||
fi
|
VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
|
||||||
elif [ "_$NVM_MODE" = '_use' ]; then
|
if [ -n "${VERSION}" ]; then
|
||||||
NVM_CURRENT="$(nvm_ls_current)"
|
if [ "_${VERSION}" != '_N/A' ] && nvm_is_valid_version "${VERSION}"; then
|
||||||
if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then
|
if [ "_${NVM_MODE}" = '_install' ]; then
|
||||||
VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
|
nvm install "${VERSION}" >/dev/null
|
||||||
if [ -n "${VERSION}" ] && ! [ "_${VERSION}" = '_N/A' ] && nvm_is_valid_version "${VERSION}"; then
|
else
|
||||||
nvm use --silent "${VERSION}" >/dev/null
|
nvm use --silent "${VERSION}" >/dev/null
|
||||||
elif nvm_rc_version >/dev/null 2>&1; then
|
fi
|
||||||
nvm use --silent >/dev/null
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
elif nvm_rc_version >/dev/null 2>&1; then
|
||||||
|
if [ "_${NVM_MODE}" = '_install' ]; then
|
||||||
|
nvm install >/dev/null
|
||||||
|
else
|
||||||
|
nvm use --silent >/dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
nvm use --silent "${NVM_CURRENT}" >/dev/null
|
||||||
fi
|
fi
|
||||||
else
|
;;
|
||||||
nvm use --silent "${NVM_CURRENT}" >/dev/null
|
*)
|
||||||
fi
|
nvm_err 'Invalid auto mode supplied.'
|
||||||
elif [ "_${NVM_MODE}" != '_none' ]; then
|
return 1
|
||||||
nvm_err 'Invalid auto mode supplied.'
|
;;
|
||||||
return 1
|
esac
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_process_parameters() {
|
nvm_process_parameters() {
|
||||||
|
Loading…
Reference in New Issue
Block a user