Skip to content

Commit

Permalink
Chain tests specific to a python-platform into single jobs (#245)
Browse files Browse the repository at this point in the history
This allows us to provide better coverage while keeping the number
of jobs under control.
  • Loading branch information
ssbarnea authored Aug 12, 2024
1 parent 665b8be commit 57099cd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
33 changes: 18 additions & 15 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ jobs:
steps:
- name: Determine matrix
id: generate_matrix
uses: coactions/dynamic-matrix@v2
uses: coactions/dynamic-matrix@main # v3
with:
min_python: "3.9"
max_python: "3.12"
default_python: "3.9"
other_names: |
lint
py39-integration
py312-integration
py39-sanity
py312-sanity
py39:tox -e py39-sanity;tox -e py39-unit; tox -e py39-integration
py310:tox -e py310-sanity;tox -e py310-unit; tox -e py310-integration
py311:tox -e py311-sanity;tox -e py311-unit; tox -e py311-integration
py312:tox -e py312-sanity;tox -e py312-unit; tox -e py312-integration
py39-macos:tox -e py39-sanity;tox -e py39-unit; tox -e py39-integration
py312-macos:tox -e py312-sanity;tox -e py312-unit; tox -e py312-integration
platforms: linux,macos
skip_explode: "1"
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os || 'ubuntu-24.04' }}
Expand Down Expand Up @@ -91,19 +94,19 @@ jobs:
sudo chmod +x /usr/local/bin/docker-compose
- name: Install Java
if: ${{ matrix.passed_name == 'integration' }}
if: "${{ startsWith(matrix.name, 'py') }}"
uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: "17"

- name: Set pre-commit cache
uses: actions/cache@v4
if: ${{ matrix.passed_name == 'lint' }}
if: ${{ matrix.name == 'lint' }}
with:
path: |
~/.cache/pre-commit
key: pre-commit-${{ matrix.name || matrix.passed_name }}-${{ hashFiles('.pre-commit-config.yaml') }}
key: pre-commit-${{ matrix.name }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up Python ${{ matrix.python_version || '3.10' }}
uses: actions/setup-python@v5
Expand All @@ -116,13 +119,13 @@ jobs:
run: |
python3 -m pip install --upgrade pip wheel tox
- name: Initialize tox envs ${{ matrix.passed_name }}
run: python3 -m tox -n --skip-missing-interpreters false -vv -e ${{ matrix.passed_name }}
timeout-minutes: 5 # average is under 1, but macos can be over 3
- run: ${{ matrix.command }}

# sequential run improves browsing experience (almost no speed impact)
- name: tox -e ${{ matrix.passed_name }}
run: python3 -m tox -e ${{ matrix.passed_name }}
- run: ${{ matrix.command2 }}
if: ${{ matrix.command2 }}

- run: ${{ matrix.command3 }}
if: ${{ matrix.command3 }}

- name: Archive logs
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -190,7 +193,7 @@ jobs:
# - name: Upload coverage data
# uses: codecov/codecov-action@v4
# with:
# name: ${{ matrix.passed_name }}
# name: ${{ matrix.name }}
# # verbose: true # optional (default = false)
# fail_ci_if_error: true
# use_oidc: true # cspell:ignore oidc
Expand Down
25 changes: 15 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Recommended usage of this file is detailed in https://github.com/ansible/eda-partner-testing/blob/main/README.md.
# The linter paths can be changed, but may result in false passes.
# {posargs} in this case would be the path to collection root relative from the .github/workflows dir (`../..`)
# cspell: ignore TOXPYTHON setenv passenv REQPASS PYTHONPYCACHEPREFIX PYTHONIOENCODING PYTHONBREAKPOINT
# cspell: ignore TOXPYTHON setenv passenv REQPASS PYTHONPYCACHEPREFIX PYTHONIOENCODING PYTHONBREAKPOINT notest

[tox]
envlist = lint, darglint, py, sanity, integration
envlist = lint, darglint, unit, sanity, integration
skipsdist = true # this repo is not a python package
isolated_build = true
requires =
Expand All @@ -20,9 +20,7 @@ deps = -r test_requirements.txt
commands_pre =
bash -c 'test "$(basename $(cd ../.. && pwd))" == ansible_collections || { echo "Repository must be cloned inside a directory structure like ansible_collections/ansible/eda in order allow ansible-test to run."; exit 3;}'
commands =
# fail-fast if psycopg in not properly installed.
python3 -c "import psycopg"
ansible-test units --venv -v --num-workers 1
tox -e sanity,unit,integration {posargs}
allowlist_externals =
bash
isolated_build = true
Expand Down Expand Up @@ -52,11 +50,9 @@ package = editable

[testenv:py{39,310,311,312,313}]
description =
Run unit tests
Run all test types: sanity, unit, integration
py{39,310,311,312,313}: with {basepython}



[testenv:lint]
deps = pre-commit
description = Run linters
Expand All @@ -75,7 +71,16 @@ description =
commands =
# risky: not safe for development it affects user setup
ansible-galaxy collection install .
pytest tests/integration -vvv -s
pytest tests/integration -vvv -s {posargs}

[testenv:unit,py{39,310,311,312,313}-unit]
description =
Run unit tests
py{39,310,311,312,313}: with {basepython}
commands =
# fail-fast if psycopg in not properly installed.
python3 -c "import psycopg"
ansible-test units --venv -v --num-workers 1

[testenv:sanity,py{39,310,311,312,313}-sanity]
deps = -r test_requirements.txt
Expand All @@ -84,4 +89,4 @@ description =
py{39,310,311,312,313}: with {basepython}
commands =
ansible --version
ansible-test sanity
ansible-test sanity {posargs}

0 comments on commit 57099cd

Please sign in to comment.