Skip to content

Commit

Permalink
Support matrix with individual comments (#99)
Browse files Browse the repository at this point in the history
* add unique-id-for-comment to readme

* add uniqueIdForComment in watermark

* 1.1.39

* changelog

* update readme
  • Loading branch information
MishaKav authored Nov 26, 2022
1 parent d009c3c commit 85136c6
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog of the Pytest Coverage Comment

## [Pytest Coverage Comment 1.1.39](https://github.com/MishaKav/pytest-coverage-comment/tree/v1.1.39)

**Release Date:** 2022-11-26

#### Changes

- Support matrix with individual comments. When you run in a matrix, and you want that every job will post a comment, you can use the `unique-id-for-comment: ${{ matrix.python-version }}`. This will post a comment for every job, and will update them on every run.

## [Pytest Coverage Comment 1.1.38](https://github.com/MishaKav/pytest-coverage-comment/tree/v1.1.38)

**Release Date:** 2022-11-26
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. runs-on
| `default-branch` | | `main` | This branch name is usefull when generate "coverageHtml", it points direct links to files on this branch (instead of commit).<br/>Usually "main" or "master" |
| `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`<br/>**Note:** In that mode the `output` for `coverage` and `color` will be for the first file only. |
| `remove-link-from-badge` | | false | When true, it will remove the link from badge to readme |
| `unique-id-for-comment` | | '' | When running in a matrix, pass the matrix value, so each comment will be updated its own comment `unique-id-for-comment: ${{ matrix.python-version }}` |

## Output Variables

Expand Down Expand Up @@ -178,6 +179,7 @@ Example GitHub Action workflow that passes all params to Pytest Coverage Comment
hide-comment: false
report-only-changed-files: false
remove-link-from-badge: false
unique-id-for-comment: python3.8
junitxml-path: ./path-to-file/pytest.xml
junitxml-title: My JUnit Xml Summary Title
```
Expand Down Expand Up @@ -264,17 +266,15 @@ Expanded comment
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
## Badge Colors

![Coverage 0-40](https://img.shields.io/badge/Coverage-20%25-red.svg) [0, 40]

![Coverage 40-60](https://img.shields.io/badge/Coverage-50%25-orange.svg) [40, 60]

![Coverage 60-80](https://img.shields.io/badge/Coverage-70%25-yellow.svg) [60, 80]

![Coverage 80-90](https://img.shields.io/badge/Coverage-85%25-green.svg) [80, 90]

![Coverage 90-100](https://img.shields.io/badge/Coverage-95%25-brightgreen.svg) [90, 100]
| Badge | Range |
| ------------------------------------------------------------------------------- | -------- |
| ![Coverage 0-40](https://img.shields.io/badge/Coverage-20%25-red.svg) | 0 - 40 |
| ![Coverage 40-60](https://img.shields.io/badge/Coverage-50%25-orange.svg) | 40 - 60 |
| ![Coverage 60-80](https://img.shields.io/badge/Coverage-70%25-yellow.svg) | 60 - 80 |
| ![Coverage 80-90](https://img.shields.io/badge/Coverage-85%25-green.svg) | 80 - 90 |
| ![Coverage 90-100](https://img.shields.io/badge/Coverage-95%25-brightgreen.svg) | 90 - 100 |

## Auto updating badge on README

Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ 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: ''
Expand Down Expand Up @@ -90,6 +90,11 @@ inputs:
default: 'false'
required: false

unique-id-for-comment:
description: 'When running in a matrix, pass the matrix value, so each comment will be updated its own comment'
default: ''
required: false

outputs:
coverage:
description: 'value indicating the coverage percentage of your report based on pytest, example 30%'
Expand Down
8 changes: 7 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17823,6 +17823,9 @@ const main = async () => {
const removeLinkFromBadge = core.getBooleanInput('remove-link-from-badge', {
required: false,
});
const uniqueIdForComment = core.getInput('unique-id-for-comment', {
required: false,
});
const defaultBranch = core.getInput('default-branch', { required: false });
const covFile = core.getInput('pytest-coverage-path', { required: false });
const covXmlFile = core.getInput('pytest-xml-coverage-path', {
Expand All @@ -17837,7 +17840,10 @@ const main = async () => {
const { context, repository } = github;
const { repo, owner } = context.repo;
const { eventName, payload } = context;
const WATERMARK = `<!-- Pytest Coverage Comment: ${context.job} -->\n`;
const watermarkUniqueId = uniqueIdForComment
? `| ${uniqueIdForComment} `
: '';
const WATERMARK = `<!-- Pytest Coverage Comment: ${context.job} ${watermarkUniqueId}-->\n`;
let finalHtml = '';

const options = {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pytest-coverage-comment",
"version": "1.1.38",
"version": "1.1.39",
"description": "Comments a pull request with the pytest code coverage badge, full report and tests summary",
"author": "Misha Kav",
"license": "MIT",
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const main = async () => {
const removeLinkFromBadge = core.getBooleanInput('remove-link-from-badge', {
required: false,
});
const uniqueIdForComment = core.getInput('unique-id-for-comment', {
required: false,
});
const defaultBranch = core.getInput('default-branch', { required: false });
const covFile = core.getInput('pytest-coverage-path', { required: false });
const covXmlFile = core.getInput('pytest-xml-coverage-path', {
Expand All @@ -48,7 +51,10 @@ const main = async () => {
const { context, repository } = github;
const { repo, owner } = context.repo;
const { eventName, payload } = context;
const WATERMARK = `<!-- Pytest Coverage Comment: ${context.job} -->\n`;
const watermarkUniqueId = uniqueIdForComment
? `| ${uniqueIdForComment} `
: '';
const WATERMARK = `<!-- Pytest Coverage Comment: ${context.job} ${watermarkUniqueId}-->\n`;
let finalHtml = '';

const options = {
Expand Down

0 comments on commit 85136c6

Please sign in to comment.