Skip to content

Commit

Permalink
Replace tox with taskfile as build tool
Browse files Browse the repository at this point in the history
As neither tox nor npm are really suitable as build build, especially
for mixed (ts/py) projects, we start using a task.

Related: ansible/vscode-ansible#511
Related: ansible/schemas#311
  • Loading branch information
ssbarnea committed Jun 17, 2022
1 parent f907ba9 commit 5c9155d
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 217 deletions.
3 changes: 3 additions & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ HORIZONTALLINE
Jenkinsfile
PYTHONHOME
TLDR
Taskfile
WSLENV
YOLO
alphanums
Expand All @@ -18,6 +19,7 @@ autoupdate
backticks
cacheable
chronographer
cmds
codeclimate
codecov
commitish
Expand All @@ -32,6 +34,7 @@ doctree
doctrees
dunamai
endfor
envdir
eqeqeq
globbing
globby
Expand Down
32 changes: 17 additions & 15 deletions .github/workflows/tox.yml → .github/workflows/task.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -33,7 +33,7 @@ jobs:
- ubuntu-latest
node-version:
- "12"
tox-target:
task-name:
- test-node12
- test-node14
- test-node16
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ change-notes-*.md
# Ignored because we support multiple versions and switch between them
.nvmrc
.node-version
.task
.venv
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >
Expand Down Expand Up @@ -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:
Expand Down
158 changes: 158 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 13 additions & 8 deletions tools/test-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 5c9155d

Please sign in to comment.