Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage Comment #72

Merged
merged 9 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -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 }}
38 changes: 36 additions & 2 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Unit tests/Coverage

name: Unit Tests and Flake

on:
push:
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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