Skip to content

Commit

Permalink
Enable coverage reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 4, 2024
1 parent 922e307 commit 3a31f35
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
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
9 changes: 6 additions & 3 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 @@ -31,15 +31,18 @@ set_env =
PIP_CONSTRAINT = {toxinidir}/.config/requirements.txt
PRE_COMMIT_COLOR = always
TERM = xterm-256color
commands_pre =
sh -c "rm -f .tox/.coverage* 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: sh -c "coverage combine -q .tox/.coverage.* && coverage xml && 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 3a31f35

Please sign in to comment.