From 76c5a1cc954bd196179ce9e67bf80d7f94644df7 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Mon, 17 Apr 2023 15:43:10 +0400 Subject: [PATCH] Replace Codecov with GitHub Actions setup Inspired by https://hynek.me/til/ditch-codecov-python and https://github.com/urllib3/urllib3/pull/2490. --- .coveragerc | 10 ---------- .github/workflows/ci.yml | 42 ++++++++++++++++++++++++++++++++++++++++ ci.sh | 6 +----- pyproject.toml | 15 ++++++++++++++ test-requirements.in | 2 +- test-requirements.txt | 34 +++++++++++++++----------------- 6 files changed, 75 insertions(+), 34 deletions(-) delete mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index f6c1f88..0000000 --- a/.coveragerc +++ /dev/null @@ -1,10 +0,0 @@ -[run] -branch=True -omit= - */setup.py - -[report] -precision = 1 -exclude_lines = - pragma: no cover - if TYPE_CHECKING: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bb2662e..bb7bf53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,12 @@ jobs: - name: Run tests run: ./ci.sh shell: bash + - name: "Upload coverage data" + uses: "actions/upload-artifact@v3" + with: + name: coverage-data + path: "empty/.coverage.*" + if-no-files-found: error Ubuntu: name: 'Ubuntu (${{ matrix.python }})' @@ -43,6 +49,12 @@ jobs: python-version: '${{ matrix.python }}' - name: Run tests run: ./ci.sh + - name: "Upload coverage data" + uses: "actions/upload-artifact@v3" + with: + name: coverage-data + path: "empty/.coverage.*" + if-no-files-found: error macOS: name: 'macOS (${{ matrix.python }})' @@ -61,3 +73,33 @@ jobs: python-version: '${{ matrix.python }}' - name: Run tests run: ./ci.sh + - name: "Upload coverage data" + uses: "actions/upload-artifact@v3" + with: + name: coverage-data + path: "empty/.coverage.*" + if-no-files-found: error + + coverage: + if: always() + runs-on: "ubuntu-latest" + needs: ["Windows", "Ubuntu", "macOS"] + steps: + - uses: actions/checkout@v3 + - name: "Use latest Python so it understands all syntax" + uses: actions/setup-python@v4 + with: + python-version: "3.x" + + - name: "Install coverage" + run: "python -m pip install --upgrade coverage[toml]" + + - name: "Download coverage data" + uses: actions/download-artifact@v3 + with: + name: coverage-data + + - name: "Combine & check coverage" + run: | + python -m coverage combine + python -m coverage report --ignore-errors --show-missing --fail-under=100 diff --git a/ci.sh b/ci.sh index 0edaa83..1b5f230 100755 --- a/ci.sh +++ b/ci.sh @@ -18,8 +18,4 @@ if [ -n "${OLD_CRYPTOGRAPHY:-}" ]; then fi mkdir empty pushd empty -INSTALLDIR=$(python -c "import os, trustme; print(os.path.dirname(trustme.__file__))") -pytest -W error -ra -s ../tests --cov="$INSTALLDIR" --cov=../tests --cov-config="../.coveragerc" - -python -m pip install codecov -codecov --tries=9999 --required -F $(uname | tr A-Z a-z) +coverage run --parallel-mode -m pytest -W error -ra -s ../tests diff --git a/pyproject.toml b/pyproject.toml index cadf0a3..74b54c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,3 +36,18 @@ warn_return_any = true warn_unreachable = true warn_unused_configs = true warn_unused_ignores = true + +[tool.coverage.run] +branch = true +omit = ["*/setup.py"] +source = ["trustme"] + +[tool.coverage.paths] +source = ["trustme", "*/trustme", "*\\trustme"] + +[tool.coverage.setup] +precision = 1 +exclude_lines = [ + "pragma: no cover", + "if TYPE_CHECKING:" +] diff --git a/test-requirements.in b/test-requirements.in index bad44a0..47b3d21 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -1,5 +1,5 @@ pytest>=6.2 -pytest-cov +coverage[toml] PyOpenSSL service-identity cryptography diff --git a/test-requirements.txt b/test-requirements.txt index 2174da7..4eda416 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,27 +1,27 @@ # -# This file is autogenerated by pip-compile with python 3.7 -# To update, run: +# This file is autogenerated by pip-compile with Python 3.8 +# by the following command: # # pip-compile test-requirements.in # -attrs==22.2.0 - # via - # pytest - # service-identity +attrs==23.1.0 + # via service-identity cffi==1.15.1 # via cryptography -coverage[toml]==5.5 - # via pytest-cov -cryptography==39.0.2 +coverage[toml]==7.2.3 + # via -r test-requirements.in +cryptography==40.0.2 # via # -r test-requirements.in # pyopenssl # service-identity +exceptiongroup==1.1.1 + # via pytest idna==3.4 # via -r test-requirements.in iniconfig==2.0.0 # via pytest -packaging==23.0 +packaging==23.1 # via pytest pluggy==1.0.0 # via pytest @@ -33,17 +33,15 @@ pyasn1-modules==0.2.8 # via service-identity pycparser==2.21 # via cffi -pyopenssl==23.0.0 +pyopenssl==23.1.1 # via -r test-requirements.in -pytest==7.2.0 - # via - # -r test-requirements.in - # pytest-cov -pytest-cov==4.0.0 +pytest==7.3.1 # via -r test-requirements.in service-identity==21.1.0 # via -r test-requirements.in six==1.16.0 # via service-identity -toml==0.10.2 - # via coverage +tomli==2.0.1 + # via + # coverage + # pytest