From 3f8b5cb14652820fe39440d17cea2899e4be2caa Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Tue, 10 Sep 2024 03:10:26 +0200 Subject: [PATCH] Integrate codecov.io We publish the test coverage reporting to codecov.io --- .github/workflows/test_coverage.yml | 2 ++ README.md | 1 + noxfile.py | 16 +++++++++++++++- pyproject.toml | 5 +++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml index 1f80a2c..3a9b498 100644 --- a/.github/workflows/test_coverage.yml +++ b/.github/workflows/test_coverage.yml @@ -27,3 +27,5 @@ jobs: # one for each of the above Python versions, # before all results are collected together - run: nox -s test-coverage + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/README.md b/README.md index 2a02e5e..60da5e3 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ The goal of the `lalib` project is to create [![Test suite: Status](https://github.com/webartifex/lalib/actions/workflows/tests.yml/badge.svg)](https://github.com/webartifex/lalib/actions/workflows/tests.yml) +[![Test coverage: codecov](https://codecov.io/github/webartifex/lalib/graph/badge.svg?token=J4LWOMVP0R)](https://codecov.io/github/webartifex/lalib) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Type checking: mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/) [![Code linting: ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) diff --git a/noxfile.py b/noxfile.py index 1ffb18d..6114c4a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,6 +1,7 @@ """Maintenance tasks run in isolated environments.""" import collections +import os import pathlib import random import re @@ -311,7 +312,20 @@ def test_coverage_report(session: nox.Session) -> None: install_pinned(session, "coverage") session.run("python", "-m", "coverage", "combine") - session.run("python", "-m", "coverage", "report", "--fail-under=100") + + if codecov_token := os.environ.get("CODECOV_TOKEN"): + install_unpinned(session, "codecov-cli") + session.run("python", "-m", "coverage", "xml", "--fail-under=0") + session.run( + "codecovcli", + "upload-process", + "--fail-on-error", + "--file=.cache/coverage/report.xml", + f"--token={codecov_token}", + ) + + else: + session.run("python", "-m", "coverage", "report", "--fail-under=100") @nox_session(name="test-docstrings", python=MAIN_PYTHON) diff --git a/pyproject.toml b/pyproject.toml index 99cf560..a65fccf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -131,6 +131,11 @@ parallel = true source = ["lalib"] +[tool.coverage.xml] + +output = ".cache/coverage/report.xml" + + [tool.flake8]