Skip to content

Commit

Permalink
Add GitHub action for coverage comment (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
wistuba authored Jan 13, 2023
1 parent f7c2317 commit 3525aa9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
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

0 comments on commit 3525aa9

Please sign in to comment.