Optimize Your CI/CD Pipeline
Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.
name: Publish Test Results
on:
push:
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Tests
run: npm test
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json
publish-unit-test-result-action
This action analyzes test result files and publishes the results on GitHub, supporting JSON, TRX, and XML formats.
What is publish-unit-test-result-action?β
The publish-unit-test-result-action
is a GitHub Action that publishes test results from your CI/CD pipelines to GitHub. It supports various test result file formats like JSON, TRX, and XML (JUnit, NUnit, XUnit) and can run on multiple platforms including Linux, macOS, and Windows.
How to Use with Different Runnersβ
Hereβs how to configure the action based on the OS runner youβre using:
For Linux:
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json
For macOS:
uses: EnricoMi/publish-unit-test-result-action/macos@v2
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json
For Windows:
uses: EnricoMi/publish-unit-test-result-action/windows@v2
with:
files: |
test-results\**\*.xml
test-results\**\*.trx
test-results\**\*.json
How to Handle Large Filesβ
If your test result files are large, you can enable large file support by setting the large_files
option to true
:
with:
large_files: true
How to Configure Pull Request Commentsβ
To automatically post comments on related pull requests based on the test results, use the comment_mode
option. For example, to comment only when test failures occur:
with:
comment_mode: failures
To disable comments entirely:
with:
comment_mode: off
How to Configure files
β
The files
option specifies the test result files to be processed. You can use glob patterns to match multiple files:
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json
How to Set a Unique check_name
β
When running the action multiple times in one workflow, set a unique check_name
to prevent results from overwriting each other:
with:
check_name: "My Test Results"
How to Ignore Test Runs Informationβ
If your test result files are very large, you can ignore run details by using the ignore_runs
option:
with:
ignore_runs: true
How to Configure GitHub Permissionsβ
In private repositories, you may need to configure permissions to allow the action to work properly. Hereβs an example of how to set permissions:
permissions:
contents: read
issues: read
checks: write
pull-requests: write
How to Set report_individual_runs
β
To see all failures instead of just the first one, enable the report_individual_runs
option:
with:
report_individual_runs: true
How to Disable Check Runsβ
If you do not want to create check runs, disable them by setting check_run
to false
:
with:
check_run: false
How to Generate Test Result Filesβ
Supported test result formats can be generated by various testing frameworks and environments. Here are a few examples:
Test Environment | Language | JUnit XML | NUnit XML | XUnit XML | TRX File | JSON File |
---|---|---|---|---|---|---|
Dart | Dart, Flutter | β | ||||
Jest | JavaScript | β | ||||
Maven | Java, Scala, Kotlin | β | ||||
Mocha | JavaScript | β | β | |||
MSTest / dotnet | .Net | β | β | β | β | |
pytest | Python | β | ||||
sbt | Scala | β |
Check your development environment for support for these formats or generate them using compatible plugins.
How to Use with Matrix Strategyβ
If your tests run in different environments using a matrix strategy, the action should run only once over all test results. Hereβs an example:
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: npm test
- name: Upload test results
uses: actions/upload-artifact@v2
with:
name: test-results
path: test-results/
publish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
with:
name: test-results
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json
How to Access Test Results as JSONβ
You can also access test results as JSON via the action's outputs or save them as a file. Hereβs an example to access the JSON output:
steps:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: |
test-results/**/*.xml
id: test_results
- name: Access Test Results JSON
run: echo "${{ steps.test_results.outputs.json }}"
This can be used to create a badge or further process the results.