Skip to content

Commit

Permalink
Enable coverage reporting (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Jan 4, 2024
1 parent 922e307 commit d9e68e1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .config/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bindep==2.11.0
cachetools==5.3.1
chardet==5.2.0
colorama==0.4.6
coverage==7.3.0
coverage==7.4.0
distlib==0.3.7
distro==1.8.0
execnet==2.0.2
Expand Down
44 changes: 37 additions & 7 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
---
name: tox

# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
on:
push: # only publishes pushes to the main branch to TestPyPI
branches: # any integration branch but not tag
- "main"
pull_request:
branches:
- "main"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

on:
create: # is used for publishing to PyPI and TestPyPI
tags: # any tag regardless of its name, no branches
- "**"
pull_request:
env:
FORCE_COLOR: 1 # tox, pytest, ansible-lint
PY_COLORS: 1

jobs:
prepare:
Expand Down Expand Up @@ -80,6 +86,30 @@ jobs:
- name: tox -e ${{ matrix.passed_name }}
run: python3 -m tox -e ${{ matrix.passed_name }}

- name: Upload coverage data
if: ${{ startsWith(matrix.passed_name, 'py') }}
uses: codecov/codecov-action@v3
with:
name: ${{ matrix.passed_name }}
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true # optional (default = false)

- name: Archive logs
uses: actions/upload-artifact@v3
with:
name: logs.zip
path: .tox/**/log/

- name: Report failure if git reports dirty status
run: |
if [[ -n $(git status -s) ]]; then
# shellcheck disable=SC2016
echo -n '::error file=git-status::'
printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY"
exit 99
fi
# https://github.com/actions/toolkit/issues/193
check: # This job does nothing and is only used for the branch protection
if: always()
permissions:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ repos:
- id: tox-ini-fmt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.9"
rev: "v0.1.11"
hooks:
- id: ruff
args:
- "--exit-non-zero-on-fix"

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.2.1
rev: v8.3.0
hooks:
- id: cspell
name: Spell check with cspell
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter"
},
Expand Down
6 changes: 6 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
codecov:
require_ci_to_pass: true
comment: false
coverage:
status:
patch: true # we want github annotations
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ documentation = "https://ansible.readthedocs.io/projects/development-environment
homepage = "https://github.com/ansible/ansible-development-environment"
repository = "https://github.com/ansible/ansible-development-environment"

[tool.coverage.report]
exclude_lines = ["if TYPE_CHECKING:", "pragma: no cover"]
# Increase it just so it would pass on any single-python run
fail_under = 42
# During development we might remove code (files) with coverage data, and we dont want to fail:
ignore_errors = true
omit = ["tests/*"]
show_missing = true
skip_covered = true
skip_empty = true

[tool.coverage.run]
concurrency = ["multiprocessing", "thread"]
# Do not use branch until bug is fixes:
# https://github.com/nedbat/coveragepy/issues/605
# branch = true
parallel = true
source = ["src"]

[tool.mypy]
files = ["src", "tests"]
strict = true
Expand Down
12 changes: 8 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ skip_missing_interpreters = true
work_dir = {env:TOX_WORK_DIR:.tox}

[testenv]
description = Run pytest under {basepython} ({envpython})
description = Run pytest under {basepython}
package = editable
extras =
test
Expand All @@ -25,21 +25,25 @@ pass_env =
TERM
USER
set_env =
COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
COVERAGE_PROCESS_START = {toxinidir}/pyproject.toml
FORCE_COLOR = 1
PIP_CONSTRAINT = {toxinidir}/.config/requirements.txt
PRE_COMMIT_COLOR = always
TERM = xterm-256color
commands_pre =
sh -c "rm -f .coverage* coverage.xml 2>/dev/null || true"
commands =
coverage run -m pytest {posargs}
sh -c "coverage combine -q .tox/.coverage.* && coverage xml || true && coverage report"
commands_post =
py,py{39,310,311,312}: sh -c "coverage combine .coverage.*"
py,py{39,310,311,312}: coverage xml
py,py{39,310,311,312}: coverage report
allowlist_externals =
rm
sh

[testenv:lint]
description = Enforce quality standards under {basepython} ({envpython})
description = Enforce quality standards under {basepython}
skip_install = true
deps =
pre-commit
Expand Down

0 comments on commit d9e68e1

Please sign in to comment.