-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* typo in docs * add multiple-files var typos * little refactor * add more pytest.xml * add multiple files * test multiple files * build * try multiple files input * update version, readme and exmaples
- Loading branch information
Showing
12 changed files
with
348 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ jobs: | |
|
||
- name: Pytest coverage comment | ||
id: coverageComment | ||
uses: MishaKav/[email protected] | ||
uses: MishaKav/pytest-coverage-comment@v1.1.0 | ||
with: | ||
pytest-coverage-path: ./data/pytest-coverage_4.txt | ||
junitxml-path: ./data/pytest_1.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Test Multipli File | ||
on: | ||
pull_request: | ||
jobs: | ||
test-multiple-files: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Pytest coverage comment | ||
uses: MishaKav/[email protected] | ||
with: | ||
multiple-files: | | ||
My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml | ||
My Title 2, ./data/pytest-coverage_4.txt, ./data/pytest_2.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,25 +8,26 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. runs-on | |
|
||
```yaml | ||
- name: Pytest coverage comment | ||
uses: MishaKav/[email protected] | ||
uses: MishaKav/pytest-coverage-comment@v1.1.0 | ||
with: | ||
pytest-coverage-path: ./pytest-coverage.txt | ||
junitxml-path: ./pytest.xml | ||
``` | ||
## Inputs | ||
| Name | Required | Default | Description | | ||
| ---------------------- | -------- | ----------------------- | ---------------------------------------------------------------------------------------- | | ||
| `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 | | ||
| `title` | | `Coverage Report` | Title for the coverage report. Useful for monorepo projects | | ||
| `badge-title` | | `Coverage` | Title for the badge icon | | ||
| `hide-badge` | | false | Hide badge with percentage | | ||
| `hide-report` | | false | Hide coverage report | | ||
| `junitxml-path` | | '' | The location of the junitxml path | | ||
| `junitxml-title` | | '' | Title for summary for junitxml | | ||
| `create-new-comment` | | false | When true, will update the same comment, otherwise will publish new comment on each run. | | ||
| Name | Required | Default | Description | | ||
| ---------------------- | -------- | ----------------------- | ----------------------------------------------------------------------------------------- | | ||
| `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 | | ||
| `title` | | `Coverage Report` | Title for the coverage report. Useful for monorepo projects | | ||
| `badge-title` | | `Coverage` | Title for the badge icon | | ||
| `hide-badge` | | false | Hide badge with percentage | | ||
| `hide-report` | | false | Hide coverage report | | ||
| `junitxml-path` | | '' | The location of the junitxml path | | ||
| `junitxml-title` | | '' | Title for summary for junitxml | | ||
| `create-new-comment` | | false | When false, will update the same comment, otherwise will publish new comment on each run. | | ||
| `multiple-files` | | '' | You can pass array of titles and files to generate single comment with table of results.<br/>Single line should look like `Title, ./path/to/pytest-coverage.txt, ./path/to/pytest.xml`<br/> example:<br/> `My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml` | | ||
|
||
## Output example | ||
|
||
|
@@ -70,18 +71,18 @@ jobs: | |
pytest --junitxml=pytest.xml --cov=app tests/ | tee pytest-coverage.txt | ||
- name: Pytest coverage comment | ||
uses: MishaKav/[email protected] | ||
uses: MishaKav/pytest-coverage-comment@v1.1.0 | ||
with: | ||
pytest-coverage-path: ./pytest-coverage.txt | ||
junitxml-path: ./pytest.xml | ||
``` | ||
|
||
Exmaple GitHub Action workflow that uses coverate percentage as output | ||
Example GitHub Action workflow that uses coverage percentage as output (see the [live workflow](../main/.github/workflows/live-test.yml)) | ||
|
||
```yaml | ||
- name: Pytest coverage comment | ||
id: coverageComment | ||
uses: MishaKav/[email protected] | ||
uses: MishaKav/pytest-coverage-comment@v1.1.0 | ||
with: | ||
pytest-coverage-path: ./pytest-coverage.txt | ||
junitxml-path: ./pytest.xml | ||
|
@@ -92,11 +93,11 @@ Exmaple GitHub Action workflow that uses coverate percentage as output | |
echo "Coverage Report - ${{ steps.coverageComment.outputs.color }}" | ||
``` | ||
|
||
Exmaple GitHub Action workflow that passes all params to Pytest Coverage Comment | ||
Example GitHub Action workflow that passes all params to Pytest Coverage Comment | ||
|
||
```yaml | ||
- name: Pytest coverage comment | ||
uses: MishaKav/[email protected] | ||
uses: MishaKav/pytest-coverage-comment@v1.1.0 | ||
with: | ||
pytest-coverage-path: ./path-to-file/pytest-coverage.txt | ||
title: My Coverage Report Title | ||
|
@@ -108,21 +109,32 @@ Exmaple GitHub Action workflow that passes all params to Pytest Coverage Comment | |
junitxml-title: My JUnit Xml Summary Title | ||
``` | ||
|
||
Exmaple GitHub Action workflow that runs pytest inside **docker** | ||
It will generate `pytest-coverage.txt` and `pytest.xml` in `/tmp` directory inside docker and share `/tmp` directory with with github workspace. | ||
Example GitHub Action workflow that runs pytest inside **docker** | ||
It will generate `pytest-coverage.txt` and `pytest.xml` in `/tmp` directory inside docker and share `/tmp` directory with GitHub workspace. | ||
|
||
```yaml | ||
- name: Run unit tests (pytest) | ||
run: | | ||
docker run -v /tmp:/tmp $IMAGE_TAG python3 -m pytest --cov-report=term-missing:skip-covered --junitxml=/tmp/pytest.xml --cov=src tests/ | tee /tmp/pytest-coverage.txt | ||
- name: Pytest coverage comment | ||
uses: MishaKav/[email protected] | ||
uses: MishaKav/pytest-coverage-comment@v1.1.0 | ||
with: | ||
pytest-coverage-path: /tmp/pytest-coverage.txt | ||
junitxml-path: /tmp/pytest.xml | ||
``` | ||
|
||
Example GitHub Action workflow that uses multiple files mode (see the [live workflow](../main/.github/workflows/multiple-files.yml)) | ||
|
||
```yaml | ||
- name: Pytest coverage comment | ||
uses: MishaKav/[email protected] | ||
with: | ||
multiple-files: | | ||
My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml | ||
My Title 2, ./data/pytest-coverage_4.txt, ./data/pytest_2.xml | ||
``` | ||
|
||
## Result example | ||
|
||
Collapsed comment | ||
|
@@ -131,6 +143,10 @@ Collapsed comment | |
Expanded comment | ||
![Result Expand Example](https://user-images.githubusercontent.com/289035/120536607-f8df1600-c3ec-11eb-9f49-c6d7571e43ac.png) | ||
|
||
Multiple Files Mode (can be useful on mono-repo projects) | ||
![Result Multiple Files Mode Example](https://user-images.githubusercontent.com/289035/122121939-ddd0c500-ce34-11eb-8546-89a8a769e065.png) | ||
|
||
|
||
## Badges colors | ||
|
||
![Coverage 0-40](https://img.shields.io/badge/Coverage-20%25-red.svg) [0, 40] | ||
|
@@ -145,5 +161,5 @@ Expanded comment | |
|
||
## Auto updating badge on README | ||
|
||
If you want auto update the coverage badge on your Readme, you can see the [workflow](../main/.github/workflows/main.yml) | ||
If you want auto-update the coverage badge on your Readme, you can see the [workflow](../main/.github/workflows/main.yml) | ||
![Auto Updating Bagde](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/MishaKav/5e90d640f8c212ab7bbac38f72323f80/raw/pytest-coverage-comment__main.json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.