Skip to content

Commit daedb4d

Browse files
Merge pull request #66 from ctrf-io/feat/community-reports
Feat/community reports
2 parents 1657bb1 + f93b00d commit daedb4d

File tree

12 files changed

+171
-8
lines changed

12 files changed

+171
-8
lines changed

.github/workflows/community.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: community-example
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
testing:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
- name: Install dependencies
18+
run: npm install
19+
- name: Build
20+
run: npm run build
21+
- name: Test community report
22+
run: node dist/core/cli.js community ctrf-reports/ctrf-report.json summary-short --title "Community report"
23+
- name: Upload test results
24+
uses: actions/upload-artifact@v4
25+
with:
26+
name: ctrf-report
27+
path: ctrf-reports/ctrf-report.json
28+
- name: Upload test results
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: custom-artifact-name
32+
path: ctrf-reports/ctrf-report-no-fails.json

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ node_modules/
33
coverage/
44
templates/
55
reports/
6+
community-reports/
67
.github/
78
.exlintrc.js

README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ your workflow:
271271
if: always()
272272
```
273273

274+
### Generating a Community Built Report
275+
276+
To use a community built report, add the `community` command to your workflow
277+
and the name of the report template:
278+
279+
```yaml
280+
- name: Publish CTRF Community Report
281+
run:
282+
npx github-actions-ctrf community path-to-your-ctrf-report.json
283+
report-template-name
284+
if: always()
285+
```
286+
287+
See the available [community reports](community-reports), or
288+
[add your own](#how-to-contribute-your-own-reports).
289+
274290
### Post a Pull Request Comment
275291

276292
To post a comment on the pull request with test results, add the `pull-request`
@@ -401,8 +417,8 @@ current workflow and job names:
401417

402418
Filtering is applied as follows:
403419

404-
- Runs from the same branch for events of type push, schedule and workflow_dispatch from the same
405-
workflow id
420+
- Runs from the same branch for events of type push, schedule and
421+
workflow_dispatch from the same workflow id
406422
- Runs from the same pull request for events of type pull_request from the same
407423
workflow id
408424

@@ -496,6 +512,10 @@ When writing your template, you can use several special Handlebars helpers:
496512

497513
- `{{eq arg1 arg2}}`: Compares two arguments and returns true if they are equal.
498514

515+
See available helpers [here](src/handlebars/helpers).
516+
517+
We welcome contributions for additional helpers.
518+
499519
### Available Properties
500520

501521
All CTRF properties are accessible via the ctrf property in your template.
@@ -528,7 +548,47 @@ The following GitHub properties are available:
528548
### Template Example
529549

530550
For inspiration on what you can create, check out the
531-
[example template](templates/custom-summary.hbs)
551+
[built-in reports](src/reports) and [community reports](community-reports)
552+
553+
### Community Reports
554+
555+
We welcome and encourage contributions of community-built reports. Community
556+
reports allow users to share custom Handlebars templates designed for specific
557+
use cases or unique report styles.
558+
559+
#### How To Contribute Your Own Reports
560+
561+
1. **Fork the Repository**
562+
Start by forking this repository to your GitHub account.
563+
564+
2. **Create a New Report Folder**
565+
Navigate to the `community-reports` directory and create a new folder named
566+
after your report (e.g., `my-custom-report`).
567+
568+
3. **Include the Following Files**
569+
Your report folder should include:
570+
571+
- **`my-custom-report.hbs`**: Your Handlebars template file. This is the core
572+
of your report.
573+
- **`README.md`**: Documentation about your report. Include the following
574+
details:
575+
- The purpose of your template.
576+
- Instructions on how to use it.
577+
- Any important considerations (e.g., required CTRF report properties).
578+
- Example output
579+
580+
4. **Submit a Pull Request**
581+
Once your report is ready, submit a pull request with a brief description of
582+
your contribution. We will review it and provide feedback if necessary.
583+
584+
#### Guidelines for Creating a Good Community Report
585+
586+
- **Be Descriptive**: Ensure your `README.md` clearly explains the report's
587+
purpose, usage, and any special requirements.
588+
- **Follow the Template Structure**: Maintain consistency with other community
589+
reports in the repository.
590+
- **Keep It Useful**: Focus on templates that solve common problems or address
591+
specific needs.
532592

533593
## Calculations
534594

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Template Name: summary-short
2+
3+
## Description
4+
5+
A brief description of what this template is for.
6+
e.g., "This template provides a summary view with key metrics and links to
7+
failing test cases."
8+
9+
---
10+
11+
## How to Use
12+
13+
Use this template by referencing its name:
14+
`summary-short`
15+
16+
Add this to your workflow file:
17+
18+
```yaml
19+
community-report-name: summary-short
20+
```
21+
22+
## Important Considerations
23+
24+
Highlight important considerations e.g. particular CTRF report properties that should be included in the report
25+
26+
## What it looks like
27+
28+
| **Tests 📝** | **Passed ✅** | **Failed ❌** | **Duration ⏱️** |
29+
| --- | --- | --- | --- |
30+
| 10 | 5 | 3 | 11.0s |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| **Tests {{getCtrfEmoji "tests"}}** | **Passed {{getCtrfEmoji "passed"}}** | **Failed {{getCtrfEmoji "failed"}}** | **Duration {{getCtrfEmoji "duration"}}** |
2+
| --- | --- | --- | --- |
3+
| {{ctrf.summary.tests}} | {{ctrf.summary.passed}} | {{ctrf.summary.failed}} | {{formatDuration ctrf.summary.start ctrf.summary.stop}} |

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-actions-ctrf",
3-
"version": "0.0.55",
3+
"version": "0.0.56",
44
"description": "View test results directly within your GitHub workflow summary and Pull Requests",
55
"main": "index.js",
66
"scripts": {
@@ -9,7 +9,7 @@
99
"format:check": "npx prettier --check .",
1010
"lint": "npx eslint . -c ./.github/linters/.eslintrc.yml",
1111
"all": "npm run format:write && npm run lint && npm run test && npm run build",
12-
"build": "tsc && copyfiles -u 2 \"src/reports/*.hbs\" dist/reports"
12+
"build": "tsc && copyfiles -u 2 \"src/reports/*.hbs\" dist/reports && copyfiles -u 2 \"community-reports/**/*.hbs\" dist/community-reports"
1313
},
1414
"bin": {
1515
"github-actions-ctrf": "./dist/core/cli.js"

src/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const GITHUB_TOKEN = process.env.GITHUB_TOKEN
22
export const GITHUB_API_URL = process.env.GITHUB_API_URL
3+
export const COMMUNITY_REPORTS_PATH = 'community-reports'

src/core/cli.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface Arguments {
1818
file?: string
1919
title?: string
2020
summary?: string
21+
communityReportName?: string
2122
annotate?: boolean
2223
rows?: number
2324
artifactName?: string
@@ -206,6 +207,21 @@ async function main(): Promise<void> {
206207
})
207208
}
208209
)
210+
.command(
211+
'community <file> <community-report-name>',
212+
'Generate a community built report from a CTRF report',
213+
yargs => {
214+
return yargs
215+
.positional('file', {
216+
describe: 'Path to the CTRF file',
217+
type: 'string'
218+
})
219+
.positional('community-report-name', {
220+
describe: 'Name of community report to use',
221+
type: 'string'
222+
})
223+
}
224+
)
209225
.command(
210226
'historical <file>',
211227
'Generate historical test results table from a CTRF report',

src/core/inputs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export function getCliInputs(args: Arguments): Inputs {
2626
suiteListReport: args._.includes('suite-list'),
2727
pullRequestReport: args._.includes('pull-request'),
2828
customReport: args._.includes('custom'),
29+
communityReport: args._.includes('community'),
30+
communityReportName: args.communityReportName || '',
2931
artifactName: args.artifactName || 'ctrf-report',
3032
annotate: args.annotate !== false,
3133
title: args.title || '',
@@ -75,6 +77,8 @@ export function getInputs(): Inputs {
7577
pullRequestReport:
7678
core.getInput('pull-request-report').toLowerCase() === 'true',
7779
customReport: core.getInput('custom-report').toLowerCase() === 'true',
80+
communityReport: core.getInput('community-report').toLowerCase() === 'true',
81+
communityReportName: core.getInput('community-report-name'),
7882
artifactName: core.getInput('artifact-name') || 'ctrf-report',
7983
annotate: core.getInput('annotate').toLowerCase() === 'true',
8084
title: core.getInput('title') || '',

0 commit comments

Comments
 (0)