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 (#624)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jan 24, 2024
1 parent 07ce1cb commit 8e4781e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ deps
devel
direnv
dirhtml
dirmngr
docker
doctree
doctrees
Expand Down Expand Up @@ -76,7 +77,6 @@ notfound
npmjs
npmrc
nvim
nvmrc
parseable
patchback
pgrep
Expand Down
47 changes: 25 additions & 22 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 All @@ -68,14 +68,18 @@ jobs:

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
shell: bash # <-- keep it here to avoid using default shell

- 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 All @@ -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]
Expand All @@ -98,13 +102,17 @@ jobs:
hostname = wsl
additional-packages:
curl
dirmngr
gawk
git
gpg
make
python3-dev
python3-pip
python3-venv
qemu-user-static
xvfb
# asdf nodejs plugin requires: dirmngr gpg curl gawk

- name: Set up Python ${{ matrix.python_version || '3.10' }}
if: "!contains(matrix.shell, 'wsl')"
Expand All @@ -120,7 +128,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 +159,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 +167,19 @@ 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"' >> ~/.bashrc
export ASDF_DIR="$HOME/.asdf"
. "$HOME/.asdf/asdf.sh"
asdf plugin add nodejs
asdf plugin add python
asdf install
asdf info
- 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
43 changes: 24 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,6 @@ tasks:
VERSION:
sh: node -p "require('./package.json').version"
cmds:
- bash -c '{{ .NODE_ENV }} nvm install'
- task: lint
- task: package
- task: docs
Expand Down Expand Up @@ -85,6 +80,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 +110,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 +125,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 +157,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 +172,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
29 changes: 10 additions & 19 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

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 @@ -154,8 +160,8 @@ command -v gh >/dev/null 2>&1 || {
sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
sudo apt-get update
sudo apt-get install gh
else
command -v dnf >/dev/null 2>&1 && sudo dnf install -y gh
fi
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 8e4781e

Please sign in to comment.