Add a pull request comment with tests results and coverage report.
Works with junit
and coverage
XML output from pytest
.
python3 -m pytest --cov-report "xml:reports/coverage/coverage.xml" --junitxml="reports/unit/unit.xml"
Add this action to your GitHub workflow as follows:
- name: Test Reports
uses: xportation/junit-coverage-report@main
with:
junit-path: ./reports/unit/unit.xml
coverage-path: ./reports/coverage/coverage.xml
You can also define github-token
used for the Github comments API.
- name: Custom Reports
uses: xportation/junit-coverage-report@main
with:
github-token: {{ $secrets.your_secret }}
junit-path: ./reports/unit/unit.xml
coverage-path: ./reports/coverage/coverage.xml
You can define custom reports using Handlebars templates.
Just add the template-path
with the file url.
- name: Custom Reports
uses: xportation/junit-coverage-report@main
with:
template-path: ./reports/custom_template.html
junit-path: ./reports/unit/unit.xml
coverage-path: ./reports/coverage/coverage.xml
The data schema provided for the template rendering:
{
coverage: {
badge,
total: {
stmts,
miss,
cover
},
items: [
{
fileUrl,
filename,
stmts,
miss,
cover,
missing: [
{
range,
url
}
]
}
]
},
junit: {
tests,
skipped,
failures,
errors,
time,
failuresItems: [
{
filename,
message
}
]
}
}
The default template is below:
<img alt="Coverage" src="{{coverage.badge}}" />
<br/>
<details>
<summary>Coverage Report</summary>
<table>
<tr>
<th>File</th>
<th>Stmts</th>
<th>Miss</th>
<th>Cover</th>
<th>Missing</th>
</tr>
<tbody>
{{#coverage.items}}
<tr>
<td><a href="{{fileUrl}}">{{filename}}</a></td>
<td>{{stmts}}</td>
<td>{{miss}}</td>
<td>{{cover}}</td>
<td>
{{#missing}}
<a href="{{url}}">{{range}}</a>
{{/missing}}
</td>
</tr>
{{/coverage.items}}
<tr>
<td><b>TOTAL</b></td>
<td><b>{{coverage.total.stmts}}</b></td>
<td><b>{{coverage.total.miss}}</b></td>
<td><b>{{coverage.total.cover}}</b></td>
<td> </td>
</tr>
</tbody>
</table>
</details>
<br/>
<table>
<tbody>
<tr>
<td><strong>Tests</strong></td>
<td><strong>Skipped</strong></td>
<td><strong>Failures</strong></td>
<td><strong>Errors</strong></td>
<td><strong>Time</strong></td>
</tr>
<tr>
<td>{{junit.tests}}</td>
<td>{{junit.skipped}} 💤</td>
<td>{{junit.failures}} ❌</td>
<td>{{junit.errors}} 🔥</td>
<td>{{junit.time}} ⏱</td>
</tr>
</tbody>
</table>
<br/>
{{#if junit.failuresItems}}
<details>
<summary>Unit Failures</summary>
<table>
<tr>
<th>Test</th>
<th>Message</th>
</tr>
<tbody>
{{#junit.failuresItems}}
<tr>
<td>{{filename}}</td>
<td><code>{{{message}}}</code></td>
</tr>
{{/junit.failuresItems}}
</tbody>
</table>
</details>
{{/if}}
This project was strongly inspired by the Pytest Coverage Comment
It's a great alternative project. You should consider it 🖤.