Skip to content

Commit

Permalink
Add coverage to PRs (#432)
Browse files Browse the repository at this point in the history
* Add workflow to comment coverage

* Rename output

* Fix low coverage + coverage report

* Update coverage command

* Update to latest agent
  • Loading branch information
cecheta authored Mar 15, 2024
1 parent a7535e7 commit f7e0388
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 18 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/comment_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Comment coverage

on:
workflow_run:
workflows: [Tests]
types:
- completed

permissions:
pull-requests: write

jobs:
comment:
name: Comment coverage
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: coverage
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Comment coverage
uses: MishaKav/pytest-coverage-comment@a1fe18e2b00c64a765568e2edb9f1706eb8fc88b
with:
pytest-xml-coverage-path: coverage.xml
junitxml-path: coverage-junit.xml
issue-number: ${{ github.event.workflow_run.pull_requests[0].number }}
coverage-path-prefix: code/
report-only-changed-files: true
50 changes: 32 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@ name: Tests

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
types:
- opened
- ready_for_review
- reopened
- synchronize
workflow_call:

jobs:
test_package:
name: Tests
runs-on: "ubuntu-20.04"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.11"
architecture: x64
- name: Install dependencies
run: |
pip install -r code/requirements.txt -r code/dev-requirements.txt -r code/backend/requirements.txt
- name: Run Unit tests
working-directory: ./code
run: python -m pytest -m "not azure and not functional"
- name: Run Functional tests
working-directory: ./code
run: python -m pytest -m "functional"
- uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.11"
architecture: x64
cache: pip
cache-dependency-path: "**/*requirements*.txt"
- name: Install dependencies
run: |
pip install -r code/requirements.txt -r code/dev-requirements.txt -r code/backend/requirements.txt
- name: Run Unit tests
working-directory: ./code
run: python -m pytest -m "not azure and not functional" --junitxml=coverage-junit.xml --cov=. --cov-report xml:coverage.xml
- uses: actions/upload-artifact@v4
with:
name: coverage
path: |
code/coverage-junit.xml
code/coverage.xml
if-no-files-found: error
- name: Run Functional tests
working-directory: ./code
run: python -m pytest -m "functional"
7 changes: 7 additions & 0 deletions code/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
omit =
tests/*

[report]
skip_empty = true
include_namespace_packages = true

0 comments on commit f7e0388

Please sign in to comment.