From 5c9155deb0d3246fbd0843360e6e19f9cc19198e Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sat, 11 Jun 2022 17:55:11 +0100 Subject: [PATCH] Replace tox with taskfile as build tool As neither tox nor npm are really suitable as build build, especially for mixed (ts/py) projects, we start using a task. Related: https://github.com/ansible/vscode-ansible/pull/511 Related: https://github.com/ansible/schemas/pull/311 --- .config/dictionary.txt | 3 + .github/workflows/{tox.yml => task.yml} | 32 ++-- .gitignore | 2 + .pre-commit-config.yaml | 6 +- Taskfile.yml | 158 ++++++++++++++++++++ package.json | 2 - tools/test-setup.sh | 21 ++- tox.ini | 189 ------------------------ 8 files changed, 196 insertions(+), 217 deletions(-) rename .github/workflows/{tox.yml => task.yml} (84%) create mode 100644 Taskfile.yml delete mode 100644 tox.ini diff --git a/.config/dictionary.txt b/.config/dictionary.txt index 3b35f5f9..336969ea 100644 --- a/.config/dictionary.txt +++ b/.config/dictionary.txt @@ -6,6 +6,7 @@ HORIZONTALLINE Jenkinsfile PYTHONHOME TLDR +Taskfile WSLENV YOLO alphanums @@ -18,6 +19,7 @@ autoupdate backticks cacheable chronographer +cmds codeclimate codecov commitish @@ -32,6 +34,7 @@ doctree doctrees dunamai endfor +envdir eqeqeq globbing globby diff --git a/.github/workflows/tox.yml b/.github/workflows/task.yml similarity index 84% rename from .github/workflows/tox.yml rename to .github/workflows/task.yml index 0bc1a3c0..373a54e3 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/task.yml @@ -1,5 +1,5 @@ # alternative KISS pipeline to bloated ci.yml, modeled after vscode-ansible one. -name: tox +name: task # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the main branch @@ -19,8 +19,8 @@ jobs: test: env: # to expose matrix job name to steps, which is not possible with expansions - JOB_NAME: ${{ matrix.name || format('{0} ({1})', matrix.tox-target, matrix.os) }} - name: ${{ matrix.name || format('{0} ({1})', matrix.tox-target, matrix.os) }} + JOB_NAME: ${{ matrix.name || format('{0} ({1})', matrix.task-name, matrix.os) }} + name: ${{ matrix.name || format('{0} ({1})', matrix.task-name, matrix.os) }} # The type of runner that the job will run on runs-on: ${{ matrix.os || 'ubuntu-latest' }} defaults: @@ -33,7 +33,7 @@ jobs: - ubuntu-latest node-version: - "12" - tox-target: + task-name: - test-node12 - test-node14 - test-node16 @@ -43,19 +43,19 @@ jobs: - false include: - name: lint - tox-target: lint + task-name: lint - name: docs - tox-target: docs + task-name: docs - name: test (wsl) # runner does not support running container - tox-target: test-without-ee + task-name: test-without-ee # https://github.com/actions/virtual-environments/issues/5151 os: windows-2019 shell: "wsl-bash {0}" - name: test (macos) os: macos-11 # runner does not support running container - tox-target: test-without-ee + task-name: test-without-ee steps: - name: Disable autocrlf @@ -76,11 +76,11 @@ jobs: # https://github.com/Vampire/setup-wsl#wsl-shell-command wsl-shell-command: "bash -i -euo pipefail" - - name: Run ./tools/test-setup.sh - run: ./tools/test-setup.sh - - - name: Install tox - run: python3 -m pip install --user tox + - name: Install Task + uses: arduino/setup-task@v1 + with: + version: 3.x + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Dump node version into .nvmrc file # save node version in .nvmrc file by looking for a pattern like @@ -98,8 +98,10 @@ jobs: with: node-version-file: '.nvmrc' - - name: tox -e ${{ matrix.tox-target }} - run: python3 -m tox -e ${{ matrix.tox-target }} + - run: task setup + + - name: task ${{ matrix.task-name }} + run: task ${{ matrix.task-name }} check: # This job does nothing and is only used for the branch protection if: always() diff --git a/.gitignore b/.gitignore index 990e2096..6f6ac42c 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ change-notes-*.md # Ignored because we support multiple versions and switch between them .nvmrc .node-version +.task +.venv diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e40de910..4606754e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,12 +50,12 @@ repos: files: "codecov.yml" pass_filenames: false - repo: https://github.com/streetsidesoftware/cspell-cli - rev: v5.9.1 + rev: v6.0.0 hooks: - id: cspell name: Spell check with cspell - repo: https://github.com/pre-commit/pre-commit-hooks.git - rev: v4.2.0 + rev: v4.3.0 hooks: - id: end-of-file-fixer exclude: > @@ -102,7 +102,7 @@ repos: docs/settings.md $ - repo: https://github.com/pre-commit/mirrors-eslint - rev: v8.14.0 + rev: v8.17.0 hooks: - id: eslint args: diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 00000000..bd9319bc --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,158 @@ +--- +# see https://taskfile.dev/#/ +version: "3" +output: group +vars: + VENV_PATH: '{{default ".venv" (env "VIRTUAL_ENV")}}' + VENV_PYTHON: '{{if (eq OS "windows")}}{{.VENV_PATH}}/Scripts/python.exe{{else}}{{.VENV_PATH}}/bin/python{{end}}' + VERSION: + sh: node -p "require('./package.json').version" + 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"; +tasks: + default: + desc: Run most commands + deps: + - lint + - package + cmds: + - bash -c '{{ .NODE_ENV }} nvm install' + - echo Done {{.VERSION}}! + docs: + desc: Build the documentation + vars: + envdir: ../.tox/docs + temp_dir: ../.tox/docs/tmp + sphinx_common_args: '-j auto --color -a -n -W --keep-going -T -d "{{.temp_dir}}/.doctrees" . "{{.envdir}}/docs_out"' + dir: docs + cmds: + - python3 -m venv ../.tox/docs + - > + source ../.tox/docs/bin/activate && + pip install "..[docs]" && + python -m sphinx -b html {{.sphinx_common_args}} + setup: + desc: Install dependencies + run: once + cmds: + - ./tools/test-setup.sh + - python3 -m pip install --user pre-commit + - npm ci + - docker pull quay.io/ansible/creator-ee:latest + - podman pull quay.io/ansible/creator-ee:latest + - pre-commit --version + - npm --version + sources: + - tools/test-setup.sh + - package.json + - Taskfile.yml + build: + desc: Build the project + deps: + - setup + cmds: + - npm run compile && sleep 1 + sources: + - package-lock.json + - package.json + - src/ + - tsconfig.json + - webpack.config.js + deps: + desc: Update dependencies + deps: + - setup + cmds: + - bash -c "PIP_CONSTRAINTS= pip-compile -q --extra docs --extra test --strip-extras --no-annotate setup.cfg -o requirements.txt" + - python3 -m pre_commit autoupdate + # bumps some developments dependencies + - npx ncu -u --dep dev + # running install after ncu is needed in order to update the lock file + - npm install + lint: + desc: Lint the project + deps: + - setup + env: + PRE_COMMIT_COLOR: always + cmds: + - python3 -m pre_commit run -a + silent: true + sources: + - "*.*" + - .config + - .github + - .vscode + - doc + - images + - src + - syntaxes + - test + - tools + test: + desc: Run all tests + deps: + - setup + cmds: + - > + source {{.VENV_PATH}}/bin/activate && + which -a ansible-lint + npm run test + interactive: true + test-node12: + desc: Run all tests using node 12 + cmds: + - bash -c '{{ .NODE_ENV }} nvm use 12' + - task: test + test-node14: + desc: Run all tests using node 14 + cmds: + - bash -c '{{ .NODE_ENV }} nvm use 14' + - task: test + test-node16: + desc: Run all tests using node 16 + cmds: + - bash -c '{{ .NODE_ENV }} nvm use 16' + - task: test + test-with-ee: + desc: Run only ee tests + deps: + - setup + cmds: + - > + source ../.tox/docs/bin/activate && + npm run test-with-ee + interactive: true + test-without-ee: + desc: Run only non-ee tests + deps: + - setup + cmds: + - > + source {{.VENV_PATH}}/bin/activate && + npm run test-without-ee + interactive: true + package: + desc: Package extension + deps: + - build + sources: + - CHANGELOG.md + - README.md + - package*.json + - out/ + generates: + - "*.vsix" + cmds: + - rm -f *.tgz + - npm pack + silent: false + pr: + desc: Opens a pull request using gh + deps: + - lint + cmds: + - gh pr create + interactive: true diff --git a/package.json b/package.json index 75141630..a70b84c0 100644 --- a/package.json +++ b/package.json @@ -79,8 +79,6 @@ "clean": "rimraf out/server && rimraf lib", "compile": "tsc -p .", "coverage": "nyc report --reporter=text-lcov > out/coverage.lcov", - "deps": "ncu -u && npm install", - "lint": "pre-commit run -a", "prepack": "npm ci && npm run compile", "//prepare": "Prepare is needed for installation from source", "prepare": "npm run compile", diff --git a/tools/test-setup.sh b/tools/test-setup.sh index 20405a04..7237f152 100755 --- a/tools/test-setup.sh +++ b/tools/test-setup.sh @@ -2,7 +2,7 @@ # This tool is used to setup the environment for running the tests. Its name # name and location is based on Zuul CI, which can automatically run it. # (cspell: disable-next-line) -set -euxo pipefail +set -euo pipefail # User specific environment # shellcheck disable=SC2076 @@ -36,17 +36,22 @@ if [ "$(which npm)" == '/mnt/c/Program Files/nodejs/npm' ]; then sudo apt-get install -y -qq -o=Dpkg::Use-Pty=0 nodejs gcc g++ make fi -which pipx || python3 -m pip install --user pipx -which -a pipx -which pre-commit || pipx install pre-commit +if [[ ! -d "${VENV_PATH:-.venv}" ]]; then + python3 -m venv "${VENV_PATH:-.venv}" +fi + +if [ -z ${VIRTUAL_ENV+x} ]; then + which -a python3 + python3 --version + # shellcheck disable=SC1091 + source "${VENV_PATH:-.venv}/bin/activate" +fi +python3 -m pip install -U pip if [[ $(uname) != MINGW* ]]; then # if we are not on pure Windows # GHA comes with ansible-core preinstalled via pipx, so we will # inject the linter into it. MacOS does not have it. - which ansible || pipx install ansible-core - - # we need pipx 1.0 as Ubuntu has a outdated/incompatible version - pipx inject --include-deps --include-apps ansible-core ansible-lint yamllint + python3 -m pip install -r requirements.txt ansible --version ansible-lint --version fi diff --git a/tox.ini b/tox.ini deleted file mode 100644 index ee598e4b..00000000 --- a/tox.ini +++ /dev/null @@ -1,189 +0,0 @@ -# spell-checker:ignore toxinidir passenv usedevelop testenv basepython envpython linkcheck changedir envdir envlist minversion toxworkdir posargs envname skipsdist setenv -[tox] -envlist = - lint - docs - test -minversion = 3.21.0 -skip_install = true -skipsdist = true -requires = - # ensure tox returns a non-zero exit code when git reports dirty: - tox-extra>=0.4.0 - -[docs] -# do not use continuation with vars, see https://github.com/tox-dev/tox/issues/2069 -sphinx_common_args = - # https://github.com/sphinx-doc/sphinx/pull/10260 - -j auto --color -a -n -W --keep-going -T -d "{temp_dir}/.doctrees" . "{envdir}/docs_out" - -[testenv] -description = - Run tests - test-node12: with node 12 - test-node14: with node 14 - test-node16: with node 16 -passenv = - CI - GITHUB_ACTIONS - HOME - SSH_AUTH_SOCK - TERM -setenv = - FORCE_COLOR=1 - NODE_VERSION=stable - node12: NODE_VERSION=12 - node14: NODE_VERSION=14 - node16: NODE_VERSION=16 - PIP_CONSTRAINTS=requirements.txt -allowlist_externals = - bash - git - node - npm - sh -# Activation of node version is not persistent and nvm works only from -# within `bash --login`, do not call nvm/npm/node without it under tox as -# you might end-up using system version, if any -# On GHA we run run tox --notest, setup/node-version and tox ... after, as -# the second one will configure the version of node that we tox dumps. -commands_pre = - {node12,node14,node16}: bash --login -c "echo {env:NODE_VERSION} > .nvmrc" -commands_post = - # restore nvm default alias to stable version - {node12,node14,node16}: bash --login -c "node --version && echo 'current' > .nvmrc" -commands = - bash --login -c "npm run test" - -skip_install = true - -# keep them, so tox 3 can lists these as additional envs: -[testenv:test-{node12,node14,node16}] -description = - Run tests - test-node12: with node 12 - test-node14: with node 14 - test-node16: with node 16 - -[testenv:test-without-ee] -description = - Run tests without execution environment ones -commands = - bash --login -c "npm run test-without-ee" - -[testenv:deps] -description = Bump all test dependencies -# Using py310 in order to make pip-compile consistent. -basepython = python3.10 -deps = - pip-tools >= 6.5.1 -commands_pre = -commands = - # dependabot supports only 'requirements.txt' filename but we use it as - # a constraints files - bash -c "PIP_CONSTRAINTS= pip-compile -q --extra docs --extra test --strip-extras --no-annotate setup.cfg -o requirements.txt" - npm run deps - -[testenv:docs] -changedir = {toxinidir}/docs -commands_pre = - # Retrieve possibly missing commits: - - git fetch --unshallow - - git fetch --tags -commands = - npm ci - npm run generate-settings-readme - {envpython} -m sphinx -b html {[docs]sphinx_common_args} - {envpython} -m sphinx -b linkcheck {[docs]sphinx_common_args} - - # Print out the output docs dir and a way to serve html: - - {envpython} -c\ - 'import pathlib;\ - docs_dir = pathlib.Path(r"{envdir}") / "docs_out";\ - index_file = docs_dir / "index.html";\ - print("\n" + "=" * 120 +\ - f"\n\nDocumentation available under:\n\n\ - \tfile://\{index_file\}\n\nTo serve docs, use\n\n\ - \t$ python3 -m http.server --directory \ - \N\{QUOTATION MARK\}\{docs_dir\}\N\{QUOTATION MARK\} 0\n\n" +\ - "=" * 120)' - -deps = - -e .[docs] -description = Build The Docs -passenv = - SSH_AUTH_SOCK -skip_install = true -usedevelop = false - - -[testenv:lint] -description = Run all linters -deps = - pre-commit >= 2.17.0 -commands_pre = -commands = - # Commands are the same as running `npm run lint`: - pre-commit run -a -skip_install = true - - -[testenv:make-changelog] -basepython = python3 -depends = - check-changelog -description = - Generate a changelog from fragments using Towncrier. Getting an - unreleased changelog preview does not require extra arguments. - When invoking to update the changelog, pass the desired version as an - argument after `--`. For example, `tox -e {envname} -- 1.3.2`. -envdir = {toxworkdir}/changelog -commands_pre = -commands = - {envpython} -m \ - towncrier.build \ - --version \ - {posargs:'[UNRELEASED DRAFT]' --draft} -deps = - towncrier == 21.3.0 -isolated_build = true -skip_install = true - - -[testenv:check-changelog] -basepython = {[testenv:make-changelog]basepython} -description = - Check Towncrier change notes -commands_pre = -commands = - {envpython} -m \ - towncrier.check \ - --compare-with origin/main \ - {posargs:} -deps = - {[testenv:make-changelog]deps} -envdir = {[testenv:make-changelog]envdir} -isolated_build = {[testenv:make-changelog]isolated_build} -skip_install = {[testenv:make-changelog]skip_install} - - -[testenv:draft-changelog] -basepython = {[testenv:make-changelog]basepython} -description = - Print out the Towncrier-managed change notes - draft for the next release to stdout -commands_pre = -commands = - # NOTE: `sh` invocation is required to suppress stderr from - # NOTE: towncrier since it does not have own CLI flags for - # NOTE: doing this. - sh -c "2>/dev/null \ - {envpython} -m \ - towncrier.build \ - --version '[UNRELEASED DRAFT]' \ - --draft" -envdir = {[testenv:make-changelog]envdir} -deps = - {[testenv:make-changelog]deps} -isolated_build = {[testenv:make-changelog]isolated_build} -skip_install = {[testenv:make-changelog]skip_install}