diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..47d9a0f4 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,19 @@ +name: Post coverage comment + +on: + workflow_run: + workflows: ["run_unit_tests"] + types: + - completed + +jobs: + test: + name: Run tests & display coverage + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' + steps: + - name: Post comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }} diff --git a/.github/workflows/run_unit_tests.yml b/.github/workflows/run_unit_tests.yml index d7a358d4..b9cd593a 100644 --- a/.github/workflows/run_unit_tests.yml +++ b/.github/workflows/run_unit_tests.yml @@ -1,5 +1,5 @@ +name: Unit tests/Coverage -name: Unit Tests and Flake on: push: @@ -38,7 +38,41 @@ jobs: # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,E402,E501,F63,F7,F82,F401,W291,W605 --max-line-length=100 --show-source --statistics # exit-zero treats all errors as warnings. - flake8 . --count --exit-zero --max-complexity=10 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=100 --statistics - name: Run unit tests run: PYTHONPATH=test python -m pytest test/ + env: + COVERAGE_FILE: ".coverage.${{ matrix.python_version }}" + + - name: Store coverage file + uses: actions/upload-artifact@v2 + with: + name: coverage + path: .coverage.${{ matrix.python_version }} + + coverage: + name: Coverage + runs-on: ubuntu-latest + needs: test + steps: + - uses: actions/checkout@v2 + + - uses: actions/download-artifact@v2 + id: download + with: + name: 'coverage' + + - name: Coverage comment + id: coverage_comment + uses: py-cov-action/python-coverage-comment-action@v3 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MERGE_COVERAGE_FILES: true + + - name: Store Pull Request comment to be posted + uses: actions/upload-artifact@v2 + if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true' + with: + name: python-coverage-comment-action + path: python-coverage-comment-action.txt diff --git a/pyproject.toml b/pyproject.toml index 4af0b99a..b82a7aff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,8 @@ target-version = ["py38", "py39", "py310"] include = '\.pyi?$' [tool.pytest.ini_options] -addopts = "--cov --cov-report html --cov-report term-missing --cov-fail-under 80" +addopts = "--cov --cov-fail-under 80" [tool.coverage.run] source = ["src"] +relative_files = true