Skip to content

Commit

Permalink
ci: add tox (#295)
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 authored Jun 15, 2023
1 parent 511996d commit 9ebe593
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 194 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`?

-----
129 changes: 74 additions & 55 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,8 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.10'
cache: 'pip'
- name: Configure environment
run: |
echo "::group::Begin snap install"
Expand All @@ -32,61 +30,68 @@ 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
- name: Run Linters
run: tox run --skip-pkg-install --no-list-dependencies -m lint
unit-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
cache: 'pip'
- 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.6' 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
# use `tox` instead of `.tox/.tox/bin/tox` to support Windows
run: tox run --skip-pkg-install --no-list-dependencies --result-json results/tox-${{ matrix.platform }}.json -m unit-tests
env:
PYTEST_ADDOPTS: "--no-header -vv -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:
python-version: ["3.8", "3.10", "3.11", "3.12-dev"]
python: [
{system-version: "3.8", tox-version: "py38"},
{system-version: "3.10", tox-version: "py310"},
{system-version: "3.11", tox-version: "py311"},
{system-version: "3.12-dev", tox-version: "py312"},
]
# does not work with canonical/setup-lxd github action (see https://github.com/canonical/craft-providers/issues/271)
runs-on: ubuntu-latest
steps:
Expand All @@ -97,11 +102,12 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python.system-version }}
cache: 'pip'
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install -U .[dev]
python -m pip install 'tox>=4.6'
echo "::endgroup::"
echo "::group::Configure LXD"
sudo groupadd --force --system lxd
Expand All @@ -114,18 +120,26 @@ jobs:
sudo iptables -I DOCKER-USER -i lxdbr0 -j ACCEPT
sudo iptables -I DOCKER-USER -o lxdbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
echo "::endgroup::"
- name: Setup Tox environments
run: tox run -e integration-${{ matrix.python.tox-version }} --notest
- name: Run integration tests on Linux
env:
CRAFT_PROVIDERS_TESTS_ENABLE_SNAP_INSTALL: 1
CRAFT_PROVIDERS_TESTS_ENABLE_LXD_INSTALL: 1
CRAFT_PROVIDERS_TESTS_ENABLE_LXD_UNINSTALL: 1
PYTEST_ADDOPTS: "--no-header -vv -rN"
run: |
export CRAFT_PROVIDERS_TESTS_ENABLE_SNAP_INSTALL=1
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/.tox/bin/tox run --skip-pkg-install --no-list-dependencies -e integration-${{ matrix.python.tox-version }}"
integration-tests-macos:
strategy:
matrix:
python-version: ["3.8", "3.10", "3.11", "3.12-dev"]
python: [
{system-version: "3.8", tox-version: "py38"},
{system-version: "3.10", tox-version: "py310"},
{system-version: "3.11", tox-version: "py311"},
{system-version: "3.12-dev", tox-version: "py312"},
]
runs-on: macos-latest
steps:
- name: Checkout code
Expand All @@ -135,11 +149,12 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python.system-version }}
cache: 'pip'
- name: Configure environment
run: |
echo "::group::pip install"
python -m pip install -U -e .[dev]
python -m pip install 'tox>=4.6'
echo "::endgroup::"
echo "::group::Install Multipass"
brew update
Expand All @@ -151,8 +166,12 @@ jobs:
sleep 20
multipass version
echo "::endgroup::"
- name: Setup Tox environments
run: tox run -e integration-${{ matrix.python.tox-version }} --notest
- name: Run integration tests on MacOS
env:
CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_INSTALL: 1
CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_UNINSTALL: 1
PYTEST_ADDOPTS: "--no-header -vv -rN"
run: |
export CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_INSTALL=1
export CRAFT_PROVIDERS_TESTS_ENABLE_MULTIPASS_UNINSTALL=1
make test-integrations
.tox/.tox/bin/tox run --skip-pkg-install --no-list-dependencies -e integration-${{ matrix.python.tox-version }}
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
Loading

0 comments on commit 9ebe593

Please sign in to comment.