Skip to content

Commit

Permalink
ci: add tox
Browse files Browse the repository at this point in the history
Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>
  • Loading branch information
mr-cal committed Jun 14, 2023
1 parent f026bee commit dcae692
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 182 deletions.
2 changes: 2 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- [ ] Have you followed the guidelines for contributing?
- [ ] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [ ] Have you successfully run `tox`?

-----
88 changes: 41 additions & 47 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
name: Tests
name: tests

on:
push:
branches:
- "main"
- "feature/*"
- "release/*"
- "hotfix/*"
- "release/*"
pull_request:

# Allows triggering the workflow manually from the Actions tab
workflow_dispatch:

jobs:
linters:
runs-on: ubuntu-latest
Expand All @@ -23,7 +20,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.10'
- name: Configure environment
run: |
echo "::group::Begin snap install"
Expand All @@ -32,57 +29,55 @@ jobs:
sudo snap install --no-wait shellcheck
echo "::endgroup::"
echo "::group::pip install"
python -m pip install -U .[dev,lint,types]
python -m pip install 'tox>=4' tox-gh
echo "::endgroup::"
echo "::group::Create virtual environments for linting processes."
tox run -m lint --notest
echo "::endgroup::"
echo "::group::Wait for snap to complete"
snap watch --last=install
echo "::endgroup::"
- name: Run black
run: |
make test-black
- name: Run ruff
run: |
make test-ruff
- name: Run codespell
run: |
make test-codespell
- name: Run mypy
run: |
make test-mypy
- name: Run pyright
run: |
make test-pyright
- name: Run shellcheck
run: |
make test-shellcheck
- name: Run yamllint
run: |
make test-yaml
unit-tests:
- name: Run Linters
run: tox run -m lint
tests:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.10", "3.11", "3.12-dev"]
runs-on: ${{ matrix.os }}
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python on ${{ matrix.platform }}
- name: Set up Python versions on ${{ matrix.platform }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: |
3.8
3.9
3.10
3.11
3.12-dev
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install -U .[dev]
python -m pip install -U -e .
python -m pip install 'tox>=4' tox-gh
echo "::endgroup::"
- name: Run unit tests
run: make test-units

mkdir -p results
- name: Setup Tox environments
run: tox run -m unit-tests --notest
- name: Test with tox
run: tox run-parallel --parallel all --parallel-no-spinner --skip-pkg-install --result-json results/tox-${{ matrix.platform }}.json -m unit-tests -- --no-header --quiet -rN
- name: Upload code coverage
uses: codecov/codecov-action@v3
with:
directory: ./results/
files: coverage*.xml
- name: Upload test results
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: test-results-${{ matrix.platform }}
path: results/
integration-tests-linux:
strategy:
matrix:
Expand All @@ -101,7 +96,7 @@ jobs:
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install -U .[dev]
python -m pip install 'tox>=4' tox-gh
echo "::endgroup::"
echo "::group::Configure LXD"
sudo groupadd --force --system lxd
Expand All @@ -120,8 +115,7 @@ jobs:
export CRAFT_PROVIDERS_TESTS_ENABLE_LXD_INSTALL=1
export CRAFT_PROVIDERS_TESTS_ENABLE_LXD_UNINSTALL=1
sg lxd -c "lxc version"
sg lxd -c "make test-integrations"
sg lxd -c "tox run -m integration-tests"
integration-tests-macos:
strategy:
matrix:
Expand All @@ -139,7 +133,7 @@ jobs:
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install -U -e .[dev]
python -m pip install 'tox>=4' tox-gh
echo "::endgroup::"
echo "::group::Install Multipass"
brew update
Expand All @@ -155,4 +149,4 @@ jobs:
run: |
export CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_INSTALL=1
export CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_UNINSTALL=1
make test-integrations
tox run -m integration-tests
104 changes: 0 additions & 104 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@


def run_apidoc(_):
from sphinx.ext.apidoc import main
from sphinx.ext.apidoc import main # type: ignore
import os
import sys

Expand Down
64 changes: 45 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ craft-providers = "craft_providers.cli:main"

[project.optional-dependencies]
dev = [
"twine",
"coverage",
"freezegun",
"logassert",
"pyfakefs",
"pytest",
"pytest-mock",
"pytest-subprocess",
"responses",
"types-requests",
"types-setuptools",
"types-pyyaml",
"coverage[toml]==7.2.7",
"freezegun==1.2.2",
"logassert==7",
"pyfakefs==5.2.2",
"pytest==7.3.1",
"pytest-cov==4.1.0",
"pytest-mock==3.10.0",
"pytest-subprocess==1.5.0",
"responses==0.23.1",
"types-requests==2.31.0.1",
"types-setuptools==67.8.0.0",
"types-pyyaml==6.0.12.10",
]
lint = [
"black",
"codespell",
"black==23.3.0",
"codespell[toml]==2.2.4",
"ruff==0.0.270",
"yamllint",
"yamllint==1.32.0",
]
types = [
"mypy",
"pyright",
"mypy[reports]==1.3.0",
"pyright==1.1.311",
]
docs = [
"sphinx",
Expand Down Expand Up @@ -80,19 +80,45 @@ exclude = [
"tests",
]



[tool.distutils.bdist_wheel]
universal = true

[tool.black]
target-version = ["py38"]

[tool.codespell]
ignore-words-list = "buildd,crate,keyserver,comandos,ro,dedent,dedented"
skip = ".tox,.git,build,.*_cache,__pycache__,*.tar,*.snap,*.png,./node_modules,./docs/_build,.direnv,.venv,venv,.vscode"
quiet-level = 3
check-filenames = true

[tool.pytest.ini_options]
minversion = "7.0"
testpaths = "tests"
xfail_strict = true

[tool.coverage.run]
branch = true
parallel = true
omit = ["tests/**"]

[tool.coverage.report]
skip_empty = true
fail_under = 95

[tool.pyright]
# strict type-checking with pyright is disabled (see #287)
# strict = ["craft_providers"]
pythonVersion = "3.8"
pythonPlatform = "Linux"

[tool.mypy]
python_version = "3.8"
exclude = [
"build",
"tests",
"results",
]
warn_unused_configs = true
warn_redundant_casts = true
strict_equality = true
Expand Down
11 changes: 0 additions & 11 deletions pyrightconfig.json

This file was deleted.

Loading

0 comments on commit dcae692

Please sign in to comment.