Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
Replace nvm with asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 23, 2024
1 parent 8a81b9d commit 31ee447
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 58 deletions.
1 change: 0 additions & 1 deletion .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ notfound
npmjs
npmrc
nvim
nvmrc
parseable
patchback
pgrep
Expand Down
39 changes: 19 additions & 20 deletions .github/workflows/task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
- "16"
task-name:
- vscode
- test-node14
- test-node16
- test
- test-node-lts
upload-artifact:
- false
name:
Expand Down Expand Up @@ -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')"
Expand Down Expand Up @@ -120,7 +124,6 @@ jobs:
~/.cache/npm
~/.cache/pip
~/.cache/yarn
~/.nvm/.cache
~/Library/Caches/pip
key: >
${{ runner.os }}-${{ matrix.task-name }}-${{ hashFiles(
Expand Down Expand Up @@ -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: |
Expand All @@ -177,6 +163,19 @@ jobs:
echo $PATH
command -v task
- name: Install asdf inside WSL
if: "contains(matrix.shell, 'wsl')"
run: |
set -ex
ls -la ~/
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.profile
export ASDF_DIR="$HOME/.asdf"
. "$HOME/.asdf/asdf.sh"
asdf --version
cat ~/.bash_profile || true
cat ~/.profile || true
- run: task setup

- name: task ${{ matrix.task-name }}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 18.19.0 20.11.0
44 changes: 25 additions & 19 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -124,26 +126,30 @@ 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:
- setup
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
Expand All @@ -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
Expand All @@ -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
Expand Down
25 changes: 8 additions & 17 deletions tools/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tools/vscode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ else
git checkout main
git pull --ff-only
fi
asdf local nodejs latest:18

unset VIRTUAL_ENV

Expand Down

0 comments on commit 31ee447

Please sign in to comment.