Skip to content

turing85/publish-report

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub license file

Github action to publish reports

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.

Components

This action is a composite action, it uses the following actions:

Action

actions/checkout@v4

marocchino/sticky-pull-request-comment@v2

actions/download-artifact@v4

phoenix-actions/test-reporting@v14

andymckay/cancel-action@0.4

Quick reference

Permission setup (for personal repositories)

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
...

Post initial comment

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
  ...

Generate test report and append message to existing comment

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
  ...

Generate test report from a downloaded artifact and append message to existing comment

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'
          ...
  ...

Complex example

For a complex example please take a look at the workflow of github.com/turing85/advent-of-code-2022

Inputs

NamesemanticsRequired?default
General Inputs

cancel-workflow-on-error

Whether the entire current workflow should be cancelled on error (i.e. when tests failed).

'false'

checkout

Whether a checkout should be performed

'false'

Comment-related Inputs

recreate-comment

Triggers the (re-)creation of the comment in a PR, that is updated with the reports.

'false'

comment-enabled

Whether a comment on the PR should be posted.

'true'

comment-header

The header to identify the PR comment. This is an invisible tag on the comment.

reports

comment-message-failure

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:

  • {0} is inputs.report-name
  • {1} is the number of successful tests
  • {2} is the number of failed tests
  • {3} is the number of skipped tests
  • {4} is the URL to the HTML-Report
<details>
  <summary><h3>😔 {0} failed</h3></summary>

  | Passed | Failed | Skipped |
  |--------|--------|---------|
  | ✅ {1} | ❌ {2} | ⚠️ {3}   |

  You can see the report [here]({4}).
</details>

comment-message-recreate

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.

comment-message-success

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:

  • {0} is inputs.report-name
  • {1} is the number of successful tests
  • {2} is the number of failed tests
  • {3} is the number of skipped tests
  • {4} is the URL to the HTML-Report
<details>
  <summary><h3>🥳 {0} passed</h3></summary>

  | Passed | Failed | Skipped |
  |--------|--------|---------|
  | ✅ {1} | ❌ {2} | ⚠️ {3}   |

  You can see the report [here]({4}).
</details>
Artifact-related Inputs

download-artifact-name

The name of the artifact to download.

''

download-artifact-pattern

The pattern of the artifact to download.

''

download-artifact-merge-multiple

If artifacts should be merged if multiple artifacts are downloaded.

'false'

Report-related Inputs

report-fail-on-error

Whether an error in a test should fail the step.

'true'

report-list-suites

Limits which test suites are listed. Supported options:

  • all
  • failed

all

report-list-tests

Limits which test cases are listed. Supported options:

  • all
  • failed
  • none

all

report-name

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".

JUnit

report-only-summary

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.

false

report-path

A glob path to the report files.

**/*.xml

report-reporter

Format of test results. Supported options:

  • dart-json
  • dotnet-trx
  • flutter-json
  • java-junit
  • jest-junit
  • mocha-json
  • mochawesome-json

java-junit

Outputs

NameSemanticstype

report-url

URL to the report in workflow checks.

string

tests-failed

Number of tests failed.

number

tests-passed

Number of tests passed.

number

tests-skipped

Number of tests skipped.

number

Showcase

Screeenshots are taken from this comment and this workflow run.

initial comment

Initial comment on a PR

first report

First report added

second report

Second report addded

junit report

JUnit Report

owasp report

OWASP report

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Marco Bungart
Marco Bungart

💻 🚧
Greg Duckworth
Greg Duckworth

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project is licensed under the Apache License 2.0. The license file can be found here.

About

This action allows us to publish reports as github-actions check and produce comments on Pull requests with a summary of the report.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •