From eedb09002cdf58216b57e89e49ec3b286b3f4b52 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Sat, 27 Apr 2024 13:20:57 +0100 Subject: [PATCH] setup coverage (#24) --- .github/workflows/main.yml | 37 +++++++++++++++++++++++++++++++++++-- .gitignore | 1 + Makefile | 7 ++++++- README.md | 1 + pyproject.toml | 2 +- requirements-dev.lock | 2 +- 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8361e537..e5e7f838 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,6 +47,8 @@ jobs: fail-fast: false matrix: python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + env: + PYTHON: ${{ matrix.python-version }} steps: - uses: actions/checkout@v4 - name: Ensure requests to production domains fail @@ -63,12 +65,44 @@ jobs: - run: rye config --set-bool behavior.use-uv=true - run: rye sync --no-lock - run: rye show + - run: mkdir coverage - run: make test + env: + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }} + - name: store coverage files + uses: actions/upload-artifact@v4 + with: + name: coverage-${{ matrix.os }}-${{ matrix.python-version }} + path: coverage + + coverage: + runs-on: ubuntu-latest + needs: [test] + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - name: get coverage files + uses: actions/download-artifact@v4 + with: + merge-multiple: true + path: coverage + - run: pip install coverage[toml] + - run: ls -lh coverage + - run: coverage combine coverage + - run: coverage xml + - uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml + env_vars: PYTHON + - run: coverage report --precision=2 --fail-under=99 # https://github.com/marketplace/actions/alls-green#why used for branch protection checks check: if: always() - needs: [lint, docs, test] + needs: [lint, docs, test, coverage] runs-on: ubuntu-latest steps: - name: Decide whether the needed jobs succeeded or failed @@ -77,7 +111,6 @@ jobs: jobs: ${{ toJSON(needs) }} release: - name: Release needs: [check] if: "success() && startsWith(github.ref, 'refs/tags/')" runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 84fbad21..f9953c33 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist __pycache__ *.env /scratch/ +/.coverage diff --git a/Makefile b/Makefile index d714fc43..f1b5850f 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,12 @@ lint: .PHONY: test # Run the tests test: - rye test + rye run coverage run -m pytest + +.PHONY: testcov # Run tests and generate a coverage report +testcov: test + @echo "building coverage html" + @rye run coverage html .PHONY: docs # Build the documentation docs: diff --git a/README.md b/README.md index 44b35fd0..2bb74809 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Pydantic Logfire — Uncomplicated Observability [![CI](https://github.com/pydantic/logfire/actions/workflows/main.yml/badge.svg?event=push)](https://github.com/pydantic/logfire/actions?query=event%3Apush+branch%3Amain+workflow%3ACI) +[![codecov](https://codecov.io/gh/pydantic/logfire/graph/badge.svg?token=735CNGCGFD)](https://codecov.io/gh/pydantic/logfire) [![pypi](https://img.shields.io/pypi/v/logfire.svg)](https://pypi.python.org/pypi/logfire) [![license](https://img.shields.io/github/license/pydantic/logfire.svg)](https://github.com/pydantic/logfire/blob/main/LICENSE) [![versions](https://img.shields.io/pypi/pyversions/logfire.svg)](https://github.com/pydantic/logfire) diff --git a/pyproject.toml b/pyproject.toml index bde2a9ed..8d9d96c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -112,12 +112,12 @@ dev-dependencies = [ "loguru", "ruff", "pyright", - "pip>=24.0", "pre-commit>=3.7.0", "mkdocs>=1.5.0", "mkdocs-material>=9.5.17", "mkdocs-glightbox>=0.3.7", "mkdocstrings-python>=1.8.0", + "coverage[toml]>=7.5.0", ] [tool.rye.scripts] diff --git a/requirements-dev.lock b/requirements-dev.lock index a0546428..f31a5463 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -44,6 +44,7 @@ click==8.1.7 colorama==0.4.6 # via griffe # via mkdocs-material +coverage==7.5.0 deprecated==1.2.14 # via opentelemetry-api # via opentelemetry-exporter-otlp-proto-http @@ -224,7 +225,6 @@ pandas==2.2.2 pathspec==0.12.1 # via black # via mkdocs -pip==24.0 platformdirs==4.2.1 # via black # via mkdocs