Skip to content

Commit

Permalink
Multi mode (#11)
Browse files Browse the repository at this point in the history
* 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
MishaKav authored Jun 15, 2021
1 parent 5aa719f commit 62195be
Show file tree
Hide file tree
Showing 12 changed files with 348 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/live-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/multiple-files.yml
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
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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)
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@ inputs:
default: ''
required: false
create-new-comment:
description: 'When true, will update the same comment, otherwise will publish new comment on each run'
description: 'When false, will update the same comment, otherwise will publish new comment on each run'
default: 'false'
required: false
multiple-files:
description: >
You can pass array of titles and files to generate single comment with table of results.
Single line should look like `Title, ./path/to/pytest-coverage.txt, ./path/to/pytest.xml`
example:
My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml
default: ''
required: false
outputs:
coverage:
description: 'value indicating the coverage percentage of your report based on pytest, example 30%'
Expand Down
Loading

0 comments on commit 62195be

Please sign in to comment.