Skip to content

Commit

Permalink
Add support for coverage xml (#81)
Browse files Browse the repository at this point in the history
* Add support to coverage XML file. (#59)

* Add coverage xml parser.
Add coverage module that choose between the TXT or XML report based on the file extension.

* Update coverage on Readme

* Revert multiple-files action description.
Restore README

* Update coverage on Readme

* Add `fast-xml-parser` in coverage xml parser.

* Restore missing README parts

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Misha Kav <[email protected]>

* apply my-changes (override fork changes)

* remove workflow for xml

* 1.1.33

* test-coverage-xml11

* change condition for "covXmlFile"

Co-authored-by: Leonardo Vitor da Silva <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 28, 2022
1 parent 0b96302 commit 6c41263
Show file tree
Hide file tree
Showing 15 changed files with 4,524 additions and 165 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/test-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ name: Test Branch
on:
workflow_dispatch:
pull_request:
push:
branches:
- test-coverage-xml
jobs:
test-branch:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Pytest coverage comment
id: coverageComment
uses: MishaKav/pytest-coverage-comment@main
uses: MishaKav/pytest-coverage-comment@add-support-for-coverage-xml
with:
pytest-coverage-path: ./data/pytest-coverage_4.txt
pytest-xml-coverage-path: ./data/coverage_1.xml
# pytest-coverage-path: ./data/pytest-coverage_4.txt
junitxml-path: ./data/pytest_1.xml

- name: Check the output coverage
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. runs-on
| --------------------------- | -------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `github-token` | ✓ | `${{github.token}}` | An alternative GitHub token, other than the default provided by GitHub Actions runner |
| `pytest-coverage-path` | | `./pytest-coverage.txt` | The location of the txt output of pytest-coverage. Used to generate the comment |
| `pytest-xml-coverage-path` | | '' | The location of coverage-xml from pytest-coverage (--cov-report "xml:coverage.xml) |
| `coverage-path-prefix` | | '' | Prefix for path when link to files in comment |
| `title` | | `Coverage Report` | Title for the coverage report. Useful for monorepo projects |
| `badge-title` | | `Coverage` | Title for the badge icon |
Expand Down Expand Up @@ -100,7 +101,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v2
Expand Down Expand Up @@ -151,13 +152,24 @@ Example GitHub Action workflow that uses coverage percentage as output (see the
echo "Not Success Test Info - ${{ steps.coverageComment.outputs.notSuccessTestInfo }}"
```

Example GitHub Action workflow that get coverage report from coverage-xml instead of coverage.txt
`pytest --cov-report "xml:coverage.xml" --cov=src tests/`

```yaml
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-xml-coverage-path: ./coverage.xml
```

Example GitHub Action workflow that passes all params to Pytest Coverage Comment

```yaml
- name: Pytest coverage comment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-coverage-path: ./path-to-file/pytest-coverage.txt
pytest-xml-coverage-path: ./path-to-file/coverage.xml
title: My Coverage Report Title
badge-title: My Badge Coverage Title
hide-badge: false
Expand Down Expand Up @@ -215,7 +227,7 @@ jobs:
update-coverage-on-readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ inputs:
description: 'The location of the txt output of pytest-coverage'
default: './pytest-coverage.txt'
required: false

pytest-xml-coverage-path:
description: 'The location of coverage-xml from pytest-coverage'
default: ''
required: false

coverage-path-prefix:
description: 'Prefix for path when link to files in comment'
Expand Down
Loading

0 comments on commit 6c41263

Please sign in to comment.