diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index dc8b827..59ea381 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -117,8 +117,6 @@ jobs: envs: name: Load tox environments runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.set-outputs.outputs.matrix }} steps: - uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0 with: @@ -142,6 +140,8 @@ jobs: --runs-on "${{ inputs.runs-on }}" --default-python "${{ inputs.default_python }}" \ --timeout-minutes "${{ inputs.timeout-minutes }}" shell: sh + outputs: + matrix: ${{ steps.set-outputs.outputs.matrix }} tox: name: ${{ matrix.name }} @@ -238,3 +238,45 @@ jobs: uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0 with: token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload coverage data to GitHub + if: ${{ (success() || failure()) && contains(matrix.coverage, 'github') && matrix.pytest == 'true' }} + uses: actions/upload-artifact@v4 + with: + name: .coverage.${{ github.sha }}-${{ runner.os }}-${{ runner.arch }}-${{ matrix.toxenv }} + path: "${{ github.workspace }}/**/.coverage" + + report_overall_test_coverage: + needs: [ tox ] + if: always() + name: report overall test coverage + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + lfs: true + submodules: ${{ inputs.submodules }} + ref: ${{ inputs.checkout_ref }} + - uses: actions/download-artifact@v4 + with: + pattern: .coverage.* + merge-multiple: true + - id: check_downloaded_files + run: | + [ "$(ls -A .coverage*)" ] && exit 0 || exit 1 + continue-on-error: true + - if: steps.check_downloaded_files.outcome == 'success' + uses: actions/setup-python@v5 + with: + python-version: "3.12" + - if: steps.check_downloaded_files.outcome == 'success' + name: generate coverage report + run: | + python -Im pip install --upgrade coverage[toml] + python -Im coverage combine + python -Im coverage report -i -m --format=markdown >> $GITHUB_STEP_SUMMARY + - if: steps.check_downloaded_files.outcome == 'success' + uses: actions/upload-artifact@v4 + with: + name: .coverage + path: .coverage diff --git a/docs/source/tox.rst b/docs/source/tox.rst index 9db7555..9459ead 100644 --- a/docs/source/tox.rst +++ b/docs/source/tox.rst @@ -159,8 +159,8 @@ This option has no effect if ``pytest`` is ``false``. coverage ^^^^^^^^ -A space separated list of coverage providers to upload to. Currently -only ``codecov`` is supported. Default is to not upload coverage +A space separated list of coverage providers to upload to, either +``codecov`` or ``github``. Default is to not upload coverage reports. See also, ``CODECOV_TOKEN`` secret. diff --git a/tools/tox_matrix.py b/tools/tox_matrix.py index 3762148..bcfe426 100644 --- a/tools/tox_matrix.py +++ b/tools/tox_matrix.py @@ -154,11 +154,16 @@ def get_matrix_item(env, global_libraries, global_string_parameters, # set pytest_flag item["pytest_flag"] = "" sep = r"\\" if platform == "windows" else "/" - if item["pytest"] == "true" and "codecov" in item.get("coverage", ""): - item["pytest_flag"] += ( - rf"--cov-report=xml:${{GITHUB_WORKSPACE}}{sep}coverage.xml ") - if item["pytest"] == "true" and item["pytest-results-summary"] == "true": - item["pytest_flag"] += rf"--junitxml ${{GITHUB_WORKSPACE}}{sep}results.xml " + if item["pytest"] == "true": + if "codecov" in item.get("coverage", ""): + item["pytest_flag"] += ( + rf"--cov --cov-report=xml:${{GITHUB_WORKSPACE}}{sep}coverage.xml " + ) + elif "github" in item.get("coverage", ""): + item["pytest_flag"] += "--cov " + + if item["pytest-results-summary"] == "true": + item["pytest_flag"] += rf"--junitxml ${{GITHUB_WORKSPACE}}{sep}results.xml " # set libraries env_libraries = env.get("libraries")