From 138035fee911e619c18674c18f123cdef7f188da Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 23 Jan 2024 17:47:27 +0000 Subject: [PATCH] Replace nvm with asdf --- .config/dictionary.txt | 1 - .github/workflows/task.yml | 67 +++++++++++++++++++------------------- .gitignore | 1 - .tool-versions | 1 + Taskfile.yml | 44 ++++++++++++++----------- tools/test-setup.sh | 25 +++++--------- tools/vscode.sh | 1 + 7 files changed, 69 insertions(+), 71 deletions(-) create mode 100644 .tool-versions diff --git a/.config/dictionary.txt b/.config/dictionary.txt index e9379439..b97080e6 100644 --- a/.config/dictionary.txt +++ b/.config/dictionary.txt @@ -76,7 +76,6 @@ notfound npmjs npmrc nvim -nvmrc parseable patchback pgrep diff --git a/.github/workflows/task.yml b/.github/workflows/task.yml index f89d3305..25a34bfa 100644 --- a/.github/workflows/task.yml +++ b/.github/workflows/task.yml @@ -41,34 +41,34 @@ jobs: node-version: - "16" task-name: - - vscode - - test-node14 - - test-node16 + # - vscode + - test + # - test-node-lts upload-artifact: - false name: - false include: - - name: lint - task-name: lint - - name: docs - task-name: docs + # - name: lint + # task-name: lint + # - name: docs + # task-name: docs - name: test-without-ee (wsl) # runner does not support running container task-name: test-without-ee # https://github.com/actions/virtual-environments/issues/5151 os: windows-2022 shell: "wsl-bash {0}" - - name: test-without-ee (macos) - os: macos-12 - # runner does not support running container - task-name: test-without-ee - skip_docker: "1" - skip_podman: "1" + # - name: test-without-ee (macos) + # os: macos-12 + # # runner does not support running container + # task-name: test-without-ee + # skip_docker: "1" + # skip_podman: "1" steps: - name: Disable autocrlf - if: "contains(matrix.os, 'windows')" + if: contains(matrix.os, 'windows') run: |- git config --global core.autocrlf false git config --global core.eol lf @@ -76,6 +76,10 @@ jobs: - uses: actions/checkout@v4 + - name: Setup asdf + if: "!contains(matrix.shell, 'wsl')" + uses: asdf-vm/actions/install@v3 + # https://github.com/marketplace/actions/setup-wsl - name: Activate WSL if: "contains(matrix.shell, 'wsl')" @@ -84,7 +88,7 @@ jobs: set-as-default: 'true' # we want to load user profile # https://github.com/Vampire/setup-wsl#wsl-shell-command - wsl-shell-command: "bash -euo pipefail" + wsl-shell-command: "bash -l -euo pipefail" # https://github.com/MicrosoftDocs/WSL/blob/main/WSL/wsl-config.md#L159 wsl-conf: | [automount] @@ -120,7 +124,6 @@ jobs: ~/.cache/npm ~/.cache/pip ~/.cache/yarn - ~/.nvm/.cache ~/Library/Caches/pip key: > ${{ runner.os }}-${{ matrix.task-name }}-${{ hashFiles( @@ -152,23 +155,6 @@ jobs: sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin task --version - - name: Dump node version into .nvmrc file - # save node version in .nvmrc file by looking for a pattern like - # node12 in job name. If pattern is not found it uses 'current' alias - if: "!contains(matrix.shell, 'wsl')" - run: > - python3 -c 'import os, re; - v = re.search("node(\d+)", os.environ.get("JOB_NAME", "")) or ["", "current"]; - print(v[1])' > .nvmrc - - - name: Use node - # as Windows executables are exposed inside WSL at top of PATH, we - # would end with broken npm script in PATH on wsl. - if: "!contains(matrix.shell, 'wsl')" - uses: actions/setup-node@v4 - with: - node-version-file: '.nvmrc' - - name: Install task inside WSL if: "contains(matrix.shell, 'wsl')" run: | @@ -177,6 +163,21 @@ jobs: echo $PATH command -v task + - name: Install asdf inside WSL + if: "contains(matrix.shell, 'wsl')" + run: | + set -ex + git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0 + echo '. "$HOME/.asdf/asdf.sh"' >> ~/.profile + echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc + export ASDF_DIR="$HOME/.asdf" + . "$HOME/.asdf/asdf.sh" + set + asdf --version + cat ~/.bash_profile || true + cat ~/.profile || true + ls -la ~/ + - run: task setup - name: task ${{ matrix.task-name }} diff --git a/.gitignore b/.gitignore index e564d662..1bb646c2 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ UNKNOWN.egg-info change-notes-*.md # Ignored because we support multiple versions and switch between them -.nvmrc .node-version .task .venv diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 00000000..4c1fdbc6 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +nodejs 18.19.0 20.11.0 diff --git a/Taskfile.yml b/Taskfile.yml index 1694fda0..5b9fe848 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -10,10 +10,6 @@ env: &env vars: HOSTNAME: sh: echo ${HOSTNAME:-localhost} - NODE_ENV: | - [ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"; - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" --silent; - [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"; EE_VERSION: sh: ./tools/get-image-version tasks: @@ -25,7 +21,7 @@ tasks: VERSION: sh: node -p "require('./package.json').version" cmds: - - bash -c '{{ .NODE_ENV }} nvm install' + - asdf local nodejs latest - task: lint - task: package - task: docs @@ -85,6 +81,11 @@ tasks: - setup cmds: - npm install -g npm@latest + # 1st node version is the implicit one and must match node version from + # vscode about dialog and be within supported range from https://www.npmjs.com/package/vscode-extension-tester + # as we want to avoid using different node versions across the projects. + # 2nd node version is used for preparing for new versions + - asdf local nodejs latest:18 latest:$(asdf nodejs resolve lts) - $VIRTUAL_ENV/bin/python -m pre_commit autoupdate # bumps some developments dependencies - npx ncu -u --dep dev @@ -110,8 +111,9 @@ tasks: - src/**/*.* - test/**/*.* - tools/**/*.* - test: - desc: Run all tests + .test: + # Keep the desc empty to hide entry when listing + # desc: Run all tests vars: ENGINE: sh: bash -c "command -v docker | head -n 1" @@ -124,18 +126,22 @@ tasks: - > source $VIRTUAL_ENV/bin/activate && command -v ansible-lint && - bash -c '{{ .NODE_ENV }} npm run test' + npm run test interactive: true - test-node14: - desc: Run all tests using node 14 + test: + desc: Run all tests using node (same version as vscode) cmds: - - bash -c '{{ .NODE_ENV }} nvm install 14' - - task: test - test-node16: - desc: Run all tests using node 16 + - bash -c 'asdf local nodejs latest:18 latest:$(asdf nodejs resolve lts)' + - task: .test + test-node-lts: + desc: Run all tests using node-lts (future) cmds: - - bash -c '{{ .NODE_ENV }} nvm install 16' - - task: test + # switch to node-lts + - bash -c 'asdf local nodejs latest:$(asdf nodejs resolve lts) latest:18' + - task: .test + - node --version + # restore implicit node version + - bash -c 'asdf local nodejs latest:18 latest:$(asdf nodejs resolve lts)' test-with-ee: desc: Run only ee tests deps: @@ -143,7 +149,7 @@ tasks: cmds: - > source $VIRTUAL_ENV/bin/activate && - bash -c '{{ .NODE_ENV }} npm run test-with-ee' + bash -c 'npm run test-with-ee' interactive: true test-without-ee: desc: Run only non-ee tests @@ -152,7 +158,7 @@ tasks: cmds: - > source $VIRTUAL_ENV/bin/activate && - bash -c '{{ .NODE_ENV }} npm run test-without-ee' + bash -c 'npm run test-without-ee' interactive: true package: desc: Package extension @@ -167,7 +173,7 @@ tasks: - "*.vsix" cmds: - rm -f *.tgz - - bash -c '{{ .NODE_ENV }} npm pack' + - bash -c 'npm pack' silent: false pr: desc: Opens a pull request using gh diff --git a/tools/test-setup.sh b/tools/test-setup.sh index 3d5fd8b4..5782f55e 100755 --- a/tools/test-setup.sh +++ b/tools/test-setup.sh @@ -54,6 +54,12 @@ log () { >&2 echo -e "${prefix}${2}${NC}" } +log notice "Install latest lts version of nodejs (used by 'node-lts' job)" +asdf install nodejs "latest:$(asdf nodejs resolve lts)" + +log notice "Report current build tool versions..." +asdf current + if [[ -f "/usr/bin/apt-get" ]]; then INSTALL=0 # qemu-user-static is required by podman on arm64 @@ -246,23 +252,9 @@ for CMD in ansible ansible-lint; do done unset CMD -command -v nvm >/dev/null 2>&1 || { - # define its location (needed) - [[ -z "${NVM_DIR:-}" ]] && export NVM_DIR="${HOME}/.nvm"; - # install if missing - [[ ! -s "${NVM_DIR:-}/nvm.sh" ]] && { - log warning "Installing missing nvm" - curl -s -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash - } - # activate nvm - # shellcheck disable=1091 - . "${NVM_DIR:-${HOME}/.nvm}/nvm.sh" - # shellcheck disable=1091 - [[ -s "/usr/local/opt/nvm/nvm.sh" ]] && . "/usr/local/opt/nvm/nvm.sh"; -} command -v npm >/dev/null 2>&1 || { log notice "Installing nodejs stable." - nvm install stable + asdf install } # Check if npm has permissions to install packages (system installed does not) # Share https://stackoverflow.com/a/59227497/99834 @@ -315,12 +307,11 @@ env: tools: ansible-lint: $(get_version ansible-lint) ansible: $(get_version ansible) + asdf: $(get_version asdf) bash: $(get_version bash) gh: $(get_version gh || echo null) git: $(get_version git) node: $(get_version node) - npm: $(get_version npm) - nvm: $(get_version nvm || echo null) pre-commit: $(get_version pre-commit) python: $(get_version python) task: $(get_version task) diff --git a/tools/vscode.sh b/tools/vscode.sh index dc1cb773..e6cc1962 100755 --- a/tools/vscode.sh +++ b/tools/vscode.sh @@ -12,6 +12,7 @@ else git checkout main git pull --ff-only fi +asdf local nodejs latest:18 unset VIRTUAL_ENV