Skip to content

Commit

Permalink
fix: merge test coverage before upload (#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi authored Feb 4, 2025
1 parent 8158143 commit 7f46b3e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 11 deletions.
68 changes: 57 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,64 @@ jobs:
${{ matrix.pydantic != '' && format('pydantic=={0} ', matrix.pydantic) || ''}}
- name: Run test suite
run: tox run --skip-pkg-install -e ${{ matrix.py }}
env:
COVERAGE_XML: ./coverage.xml
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-24.04' || matrix.os == ''
uses: codecov/codecov-action@v5
- name: Rename coverage report file
run: |
import os; import sys
os.rename(f".tox/.coverage.${{ matrix.py }}", f".tox/.coverage.${{ matrix.py }}-${{ matrix.os }}-${{ matrix.isort }}-${{ matrix.black }}-${{ matrix.pydantic }}")
shell: python
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
flags: unittests
files: ./coverage.xml
fail_ci_if_error: true
env_vars: OS,PY,ISORT
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
include-hidden-files: true
name: .coverage.${{ matrix.py }}.${{ matrix.os }}.${{ matrix.isort }}.${{ matrix.black }}.${{ matrix.pydantic }}
path: ".tox/.coverage.*"
retention-days: 3

coverage:
name: Combine coverage
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install hatch
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
- name: Build package to generate version
run: uv build --python 3.13 --python-preference only-managed --wheel . --out-dir dist
- name: Setup coverage tool
run: tox -e coverage --notest
env:
UV_PYTHON_PREFERENCE: only-managed
- name: Download coverage data
uses: actions/download-artifact@v4
with:
path: .tox
pattern: .coverage.*
merge-multiple: true
- name: Combine and report coverage
run: tox -e coverage --skip-pkg-install
env:
UV_PYTHON_PREFERENCE: only-managed
- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-report
path: .tox/htmlcov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
flags: unittests
files: .tox/coverage.xml
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
check:
name: tox env ${{ matrix.tox_env }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ scripts.datamodel-codegen = "datamodel_code_generator.__main__:main"

[dependency-groups]
dev = [
{ include-group = "coverage" },
{ include-group = "docs" },
{ include-group = "fix" },
{ include-group = "pkg-meta" },
Expand Down Expand Up @@ -89,6 +90,10 @@ docs = [
]
fix = [ "pre-commit>=3.5" ]
pkg-meta = [ "check-wheel-contents>=0.6.1", "twine>=6.1", "uv>=0.5.22" ]
coverage = [
"coverage[toml]>=7.6.1",
"diff-cover>=7.7",
]

[tool.hatch]
build.dev-mode-dirs = [ "." ]
Expand Down
24 changes: 24 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ commands =
check-wheel-contents --no-config {env_tmp_dir}
dependency_groups = pkg-meta

[testenv:coverage]
description = combine coverage files and generate diff (against DIFF_AGAINST defaulting to origin/main)
skip_install = true
extras =
parallel_show_output = true
pass_env =
DIFF_AGAINST
set_env =
COVERAGE_FILE = {toxworkdir}/.coverage
commands =
coverage combine
coverage report --skip-covered --show-missing
coverage xml -o {toxworkdir}/coverage.xml
coverage html -d {toxworkdir}/htmlcov
diff-cover --compare-branch {env:DIFF_AGAINST:origin/main} {toxworkdir}/coverage.xml
depends =
3.13
3.12
3.11
3.10
3.9
3.8
dependency_groups = coverage

[testenv:type]
description = run type check on code base
commands =
Expand Down
14 changes: 14 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f46b3e

Please sign in to comment.