This action allows us to publish reports as github-actions check and produce comments on Pull requests with a summary of the report.
By identifying comments through comment-header
(which will be transformed to an invisible html
comment, containing the comment-header
to identify comments controlled by this action), we can update an existing comment, adding more information as new reports get available over the run of a workflow.
This action is a composite action, it uses the following actions:
Action |
---|
name: My Workflow
...
permissions:
actions: write # Necessary to cancel workflow executions
checks: write # Necessary to write reports
pull-requests: write # Necessary to comment on PRs
...
This snippet will post a comment with the given comment-header
to the PR that triggered the workflow execution. Any existing comments with the same comment-header
will be hidden as OUTDATED
:
jobs:
...
recreate-comment:
runs-on: ubuntu-latest
steps:
- name: Publish Report
uses: turing85/publish-report@v2
with:
checkout: 'true'
comment-header: my-comment-header
comment-message-recreate: Hello
recreate-comment: true
...
The report will be generated from the files selected by the glob pattern in pattern-path
. The name of the report will be report-name
+ " Report"
.
If all tests succeeded, the message comment-message-success
will be appended to the comment with the given comment-header
. If tests failed, the message in comment-message-failure
will be appended to the comment with the given comment-header
.
We set the execution of the Publish Report
step to if: ${{ always() }}
so that it is also executed when tests fail (and we get a report).
jobs:
...
test:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4
...
- name: Run Tests
...
continue-on-error: true # the publish step will fail, so we get a report when tests failed as well
...
...
- name: Publish Report
uses: turing85/publish-report@v2
if: ${{ always() }}
with:
# cancel-workflow-on-error: 'false' # If we do not want to cancel the whole workflow execution on error
# checkout: 'true' # not needed; project is already checked out
comment-header: my-comment-header
comment-message-success: |
YAY! {0} passed!
{1} tests were successful, {2} tests failed, {3} test were skipped.
The report can be found [here]({4}).
comment-message-failure: |
On no! {0} failed!
{1} tests were successful, {2} tests failed, {3} test were skipped.
The report can be found [here]({4}).
report-fail-on-error: true # to fail when tests failed
report-name: Tests
report-path: '**/target/surefire-reports/TEST*.xml'
report-reporter: java-junit
...
When we have a scenario where we cannot or do not want the report generation the same job as the test, we can upload the test artifacts via actions/upload-artifact
. We can then execute report generation in a separate step, downloading said test artifacts.
Notice that the name
and path
used in action actions/upload-artifact
correlates with download-artifact-name
and report-path
in action turing/publish-report
.
We should configure the test
job so that it does not fail when tests fail. This guarantees that the test-report
job is executed, and can fail (as long as report-fail-on-error
is not set to 'false'
).
...
jobs:
...
test:
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v4
...
- name: Run Tests
...
...
- name: Upload test artifacts
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: test-report
path: '**/target/*-reports/TEST*.xml'
if-no-files-found: error
retention-days: 2
test-report:
runs-on: ubuntu-latest
needs:
...
- test
...
steps:
- name: Publish Report
uses: turing85/publish-report@v2
with:
...
checkout: true
...
download-artifact-name: test-report
report-path: '**/target/surefire-reports/TEST*.xml'
...
...
For a complex example please take a look at the workflow of github.com/turing85/advent-of-code-2022
Name | semantics | Required? | default |
---|---|---|---|
General Inputs | |||
|
Whether the entire current workflow should be cancelled on error (i.e. when tests failed). | ✅ |
|
|
Whether a checkout should be performed | ✅ |
|
Comment-related Inputs | |||
|
Triggers the (re-)creation of the comment in a PR, that is updated with the reports. | ✅ |
|
|
Whether a comment on the PR should be posted. | ✅ |
|
|
The header to identify the PR comment. This is an invisible tag on the comment. | ✅ |
|
|
Message appended to the comment posted on the PR after the tests failed. The message can be templated for replacement. The format feature of github-expressions is used to replace placeholders. The following placeholder-mapping applies:
|
✅ |
<details>
<summary><h3>😔 {0} failed</h3></summary>
| Passed | Failed | Skipped |
|--------|--------|---------|
| ✅ {1} | ❌ {2} | ⚠️ {3} |
You can see the report [here]({4}).
</details> |
|
Initial text for the comment posted on the PR. Subsequent messages will be appended. | ✅ |
## 🚦Reports for run [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})🚦
Reports will be posted here as they get available. |
|
Message appended to the comment posted on the PR after the tests succeed. The message can be templated for replacement. The format feature of github-expressions is used to replace placeholders. The following placeholder-mapping applies:
|
✅ |
<details>
<summary><h3>🥳 {0} passed</h3></summary>
| Passed | Failed | Skipped |
|--------|--------|---------|
| ✅ {1} | ❌ {2} | ⚠️ {3} |
You can see the report [here]({4}).
</details> |
Artifact-related Inputs | |||
|
The name of the artifact to download. | ✅ |
|
|
The pattern of the artifact to download. | ✅ |
|
|
If artifacts should be merged if multiple artifacts are downloaded. | ✅ |
|
Report-related Inputs | |||
|
Whether an error in a test should fail the step. | ✅ |
|
|
Limits which test suites are listed. Supported options:
|
✅ |
|
|
Limits which test cases are listed. Supported options:
|
✅ |
|
|
The name of the report. The Text "Report" will be appended to form the report name that is attached to the check. So if we pass "JUnit" as report-name, the corresponding report will be called "JUnit Report". |
✅ |
|
|
Allows you to generate only the summary. If enabled, the report will contain a table listing each test results file and the number of passed, failed, and skipped tests. Detailed listing of test suites and test cases will be skipped. |
✅ |
|
|
A glob path to the report files. | ✅ |
|
|
Format of test results. Supported options:
|
✅ |
|
Name | Semantics | type |
---|---|---|
|
URL to the report in workflow checks. |
|
|
Number of tests failed. |
|
|
Number of tests passed. |
|
|
Number of tests skipped. |
|
Screeenshots are taken from this comment and this workflow run.
Initial comment on a PR |
First report added |
Second report addded |
JUnit Report |
OWASP report |
Thanks goes to these wonderful people (emoji key):
Marco Bungart 💻 🚧 |
Greg Duckworth 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
This project is licensed under the Apache License 2.0. The license file can be found here.