Overview of CTRF Core
mainctrf package, maintained separately to resolve CommonJS (CJS) compatibility issues.repository·main·Indexed 18 days ago
https://github.com/ctrf-io/github-test-reporterA tool for integrating detailed test results into GitHub Actions workflows. It enables developers to view summaries, failure analyses, flaky test detection, and AI-driven insights within job summaries, Pull Request comments, and status checks. Supports CTRF and JUnit JSON formats, custom Handlebars templates, and community-built reports like cobra-report, failed-detailed, and summary-short.
ctrf package, maintained separately to resolve CommonJS (CJS) compatibility issues.When using the cobra-report template, keep the following in mind:
getCtrfEmoji, formatMessage, and anyFailedTests) being available in the environment.failed status.When building custom reports, you can access GitHub-specific metadata using the github property within your template. This allows you to inject workflow information, repository details, pull request data, and sender information directly into your report.
Commonly used properties include:
github.workflow, github.runId, github.runNumber.github.repository.name, github.repository.fullName, github.repository.htmlUrl.github.pullRequest.number, github.pullRequest.title, github.pullRequest.state (available during PR events).github.actor, github.sender.login.Note: The availability of certain properties depends on the event that triggered the workflow. For example, github.pullRequest is only populated during pull request events.
<!-- Example usage in a template -->
<h1>Report for {{github.repository.fullName}}</h1>
<p>Workflow: {{github.workflow}} (Run #{{github.runNumber}})</p>If you prefer to manage the reporter as a project dependency, install it via npm. Once installed, you can execute it directly from your node_modules or by defining a script in your package.json.
# Install the package
npm install github-actions-ctrf
# Run via node_modules path
./node_modules/.bin/github-actions-ctrf path-to-your-ctrf-report.jsonThe Failed Report focuses exclusively on failed test cases, providing a concise summary of each failure including the test name and the failure message.
- name: Publish Test Report
uses: ctrf-io/github-test-reporter@v1
with:
report-path: './ctrf/*.json'
failed-report: true
if: always()You can define how the GitHub Actions summary or Pull Request comment is presented by using a Handlebars template. This allows you to include custom markdown and leverage data from your CTRF report and GitHub properties for dynamic output.
To use the custom summary method, you must provide two arguments to the command:
.hbs) template file.In a GitHub Actions workflow, use the custom command as shown below:
- name: Publish CTRF Custom summary
run: |
npx github-actions-ctrf custom path-to-your-ctrf-report.json path-to-your-handlebars-template.hbs
if: always()You can post test results directly as a comment on a Pull Request.
Use the pull-request command. This requires the GITHUB_TOKEN environment variable with write permissions for pull requests.
- name: Publish CTRF pull request comment
run: npx github-actions-ctrf pull-request path-to-your-ctrf-report.json
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}You can combine the pull-request command with any view command using the --pull-request flag. For example, to post a flaky-rate view:
npx github-actions-ctrf flaky-rate ctrf-report.json --pull-request--on-fail-only: Post the comment only if there are failed tests.--update-comment: If true, appends the new report to an existing tagged comment instead of creating a new one.--overwrite-comment: If true, replaces the entire content of an existing tagged comment.--comment-tag <string>: A unique identifier used to find, update, or overwrite specific comments (e.g., using ${{ github.workflow }}-${{ github.job }}).To see all available properties for your specific workflow run, you can print the entire github context to your workflow logs using jq. This is useful for discovering the exact structure of the github.context object and other properties available to your template.
Add this step to your GitHub Actions workflow file:
- name: Print GitHub Context
env:
CONTEXT: ${{ toJson(github) }}
run: echo "$CONTEXT" | jq .You can leverage pre-built reports from the community by setting community-report: true and specifying a community-report-name (e.g., summary-short).
- name: Publish Test Report
uses: ctrf-io/github-test-reporter@v1
with:
report-path: './ctrf/*.json'
community-report: true
community-report-name: summary-short
if: always()The GitHub Report provides a test report that follows the GitHub Design System, using GitHub icons and color schemes for a native look and feel. It includes a summary of results and expandable sections for failed, flaky, skipped, and pending tests, along with git and action context.
- name: Publish Test Report
uses: ctrf-io/github-test-reporter@v1
with:
report-path: './ctrf/*.json'
github-report: true
if: always()If you need to process the enriched CTRF report further, or if your reports are larger than 1MB, use the write-ctrf-to-file input. This exposes the internal processed CTRF report that has been enriched with properties used by the GitHub Test Reporter.
- name: Write CTRF to File
uses: ctrf-io/github-test-reporter@v1
with:
report-path: './ctrf/*.json'
write-ctrf-to-file: './ctrf/ctrf-report.json'
if: always()The Summary Delta Report provides a concise table overview of test statuses (passed, failed, skipped, flaky, etc.) and includes a comparison to a baseline. This allows you to see changes (increases or decreases) in test counts and duration compared to previous results.
- name: Publish Test Report
uses: ctrf-io/github-test-reporter@v1
with:
report-path: './ctrf/*.json'
summary-delta-report: true
if: always()