Home

Awesome

<div align="center"> :octocat: </div> <h1 align="center"> action-junit-report </h1> <p align="center"> ... reports JUnit test results as GitHub pull request check. </p> <div align="center"> <img src=".github/images/action.png"/> </div> <div align="center"> <a href="https://github.com/mikepenz/action-junit-report"> <img src="https://github.com/mikepenz/action-junit-report/workflows/CI/badge.svg"/> </a> </div> <br />
<p align="center"> <a href="#whats-included-">What's included 🚀</a> &bull; <a href="#setup">Setup 🛠️</a> &bull; <a href="#sample-%EF%B8%8F">Sample 🖥️</a> &bull; <a href="#contribute-">Contribute 🧬</a> &bull; <a href="#license">License 📓</a> </p>

What's included 🚀

This action processes JUnit XML test reports on pull requests and shows the result as a PR check with summary and annotations.

Based on action for Surefire Reports by ScaCap

Setup

Configure the workflow

name: build
on:
  pull_request:

jobs:
  build:
    name: Build and Run Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
      - name: Build and Run Tests
        run: # execute your tests generating test results
      - name: Publish Test Report
        uses: mikepenz/action-junit-report@v5
        if: success() || failure() # always run even if the previous step fails
        with:
          report_paths: '**/build/test-results/test/TEST-*.xml'

Inputs

InputDescription
report_pathsOptional. Glob expression to junit report paths. Defaults to: **/junit-reports/TEST-*.xml.
tokenOptional. GitHub token for creating a check run. Set to ${{ github.token }} by default.
test_files_prefixOptional. Prepends the provided prefix to test file paths within the report when annotating on GitHub.
exclude_sourcesOptional. Provide , seperated array of folders to ignore for source lookup. Defaults to: /build/,/__pycache__/
check_nameOptional. Check name to use when creating a check run. The default is JUnit Test Report.
suite_regexREMOVED (as of v5). Instead use check_title_template and configure: {{BREAD_CRUMB}}{{SUITE_NAME}}/{{TEST_NAME}}
commitOptional. The commit SHA to update the status. This is useful when you run it with workflow_run.
fail_on_failureOptional. Fail the build in case of a test failure.
require_testsOptional. Fail if no test are found.
require_passed_testsOptional. Fail if no passed test are found. (This is stricter than require_tests, which accepts skipped tests).
include_passedOptional. By default the action will skip passed items for the annotations. Enable this flag to include them.
check_retriesOptional. If a testcase is retried, ignore the original failure.
check_title_templateOptional. Template to configure the title format. Placeholders: {{FILE_NAME}}, {{SUITE_NAME}}, {{TEST_NAME}}, {{CLASS_NAME}}, {{BREAD_CRUMB}}.
bread_crumb_delimiterOptional. Defines the delimiter characters between the breadcrumb elements. Defaults to: /.
summaryOptional. Additional text to summary output
check_annotationsOptional. Defines if the checks will include annotations. If disabled skips all annotations for the check. (This does not affect annotate_only, which uses no checks).
update_checkOptional. Uses an alternative API to update checks, use for cases with more than 50 annotations. Default: false.
annotate_onlyOptional. Will only annotate the results on the files, won't create a check run. Defaults to false.
transformersOptional. Array of Transformers offering the ability to adjust the fileName. Defaults to: [{"searchValue":"::","replaceValue":"/"}]
job_summaryOptional. Enables the publishing of the job summary for the results. Defaults to true. May be required to disable Enterprise Server
detailed_summaryOptional. Include table with all test results in the summary. Defaults to false.
flaky_summaryOptional. Include table with all falky results in the summary. Defaults to false.
group_suiteOptional. If enabled, will group the testcases by test suite in the detailed_summary. Defaults to false.
commentOptional. Enables a comment being added to the PR with the summary tables (Respects the summary configuration flags). Defaults to false.
updateCommentOptional. If a prior action run comment exists, it is updated. If disabled, new comments are creted for each run. Defaults to true.
annotate_noticeOptional. Annotate passed test results along with warning/failed ones. Defaults to false. (Changed in v3.5.0)
follow_symlinkOptional. Enables to follow symlinks when searching test files via the globber. Defaults to false.
job_nameOptional. Specify the name of a check to update
annotations_limitOptional. Specify the limit for annotations. This will also interrupt parsing all test-suites if the limit is reached. Defaults to: No Limit.
skip_annotationsOptional. Setting this flag will result in no annotations being added to the run. Defaults to false.

Common Configurations

<details><summary><b>Common report_paths</b></summary> <p> </p> </details>

If you observe out-of-memory errors, follow the below configuration suggestion.

[!TIP] FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

<details><summary><b>Increase Node Heap Memory</b></summary> <p>

If you encounter an out-of-memory from Node, such as

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

you can increase the memory allocation by setting an environment variable

- name: Publish Test Report
  uses: mikepenz/action-junit-report@v5
  env:
    NODE_OPTIONS: "--max_old_space_size=4096"
  if: success() || failure() # always run even if the previous step fails
  with:
    report_paths: '**/build/test-results/test/TEST-*.xml'
</p> </details>

Action outputs

After action execution it will return the test counts as output.

# ${{steps.{CHANGELOG_STEP_ID}.outputs.total}}

A full set list of possible output values for this action.

OutputDescription
outputs.totalThe total number of test cases covered by this test-step.
outputs.passedThe number of passed test cases.
outputs.skippedThe number of skipped test cases.
outputs.failedThe number of failed test cases.
outputs.summaryThe short summary of the junit report. In html format (as also constructed by GitHub for the summary).
outputs.detailed_summaryThe full table with all test results in a summary. In html format (as also constructed by GitHub for the summary).
outputs.flaky_summaryThe full table with all flaky results in a summary. In html format (as also constructed by GitHub for the summary).

PR run permissions

The action requires write permission on the checks. If the GA token is read-only (this is a repository configuration) please enable write permission via:

permissions:
  checks: write
  pull-requests: write # only required if `comment: true` was enabled

Additionally for security reasons, the github token used for pull_request workflows is marked as read-only. If you want to post checks to a PR from an external repository, you will need to use a separate workflow which has a read/write token, or use a PAT with elevated permissions.

<details><summary><b>Example</b></summary> <p>
name: build
on:
  pull_request:

jobs:
  build:
    name: Build and Run Tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v3
      - name: Build and Run Tests
        run: # execute your tests generating test results
      - name: Upload Test Report
        uses: actions/upload-artifact@v3
        if: always() # always run even if the previous step fails
        with:
          name: junit-test-results
          path: '**/build/test-results/test/TEST-*.xml'
          retention-days: 1

---
name: report
on:
  workflow_run:
    workflows: [ build ]
    types: [ completed ]

permissions:
  checks: write

jobs:
  checks:
    runs-on: ubuntu-latest
    steps:
      - name: Download Test Report
        uses: dawidd6/action-download-artifact@v2
        with:
          name: junit-test-results
          workflow: ${{ github.event.workflow.id }}
          run_id: ${{ github.event.workflow_run.id }}
      - name: Publish Test Report
        uses: mikepenz/action-junit-report@v5
        with:
          commit: ${{github.event.workflow_run.head_sha}}
          report_paths: '**/build/test-results/test/TEST-*.xml'

This will securely post the check results from the privileged workflow onto the PR's checks report.

</p> </details>

Sample 🖥️

<div align="center"> <img src=".github/images/annotated.png"/> </div> <div align="center"> <img src=".github/images/annotations.png"/> </div>

Contribute 🧬

# Install the dependencies  
$ npm install

# Verify lint is happy
$ npm run lint -- --fix

# Build the typescript and package it for distribution
$ npm run build && npm run package

# Run the tests, use to debug, and test it out
$ npm test

Credits

Original idea and GitHub Actions by: https://github.com/ScaCap/action-surefire-report

Other actions

License

Copyright (C) 2024 Mike Penz

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.