How to Post Test Results as a Check Run in GitHub Actions
A failing test buried in a 2,000-line log is hard to find; a check run surfaces the failures right on the PR.
Emit a JUnit XML report, then use a test-reporter action to create a check run with per-test annotations on the pull request.
Steps
- Configure your test runner to emit JUnit XML.
- Run tests with
if: always()so a failure still produces the report. - Use a reporter action to publish the XML as a check run.
- Grant
checks: writepermission.
Workflow
.github/workflows/test-report.yml
name: Test Report
on: [pull_request]
permissions:
contents: read
checks: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '20' }
- run: npm ci
- run: npm test -- --reporters=jest-junit
env: { JEST_JUNIT_OUTPUT_NAME: junit.xml }
- if: always()
uses: dorny/test-reporter@v1
with:
name: Jest Tests
path: junit.xml
reporter: jest-junitRelated guides
How to Gate Merges on Required Checks in GitHub ActionsMake a GitHub Actions job a required status check so a PR cannot merge until it passes, using a stable aggreg…
How to Set a Commit Status from GitHub ActionsSet a custom commit status from GitHub Actions with the GITHUB_TOKEN and the statuses API, so an external che…