Skip to content

Commit d581f3a

Browse files
committed
Merge branch 'main' of github.com:ctrf-io/github-test-reporter into issue221
2 parents 6978621 + 195d91e commit d581f3a

File tree

11 files changed

+66
-5
lines changed

11 files changed

+66
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ For more advanced usage, there are several inputs available.
153153
on-fail-only: false # Add a pull request comment only if tests fail. Default is false
154154
exitOnNoFiles: false # Exit the workflow with a failure status if no test files are found. Default is false
155155
exit-on-fail: false # Exit the workflow with a failure status if any tests fail. Default is false
156+
exit-on-empty: false # Exit the workflow with a failure status if no tests are found. Default is false
156157
use-suite-name: false # Prefix test names with the suite name for better grouping. Default is false
157158
collapse-large-reports: false # Collapse large reports (test-table and test-list) for better readability. Default is false
158159
update-comment: false # Update existing Pull Request comment. Default is false
@@ -320,7 +321,7 @@ Add the following to your workflow file:
320321
with:
321322
report-path: './ctrf/*.json'
322323
community-report: true
323-
communty-report-name: summary-short
324+
community-report-name: summary-short
324325
if: always()
325326
```
326327

__tests__/ctrf/report-preparation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ function createSingleReportInputs(): Inputs {
503503
onFailOnly: false,
504504
exitOnNoFiles: false,
505505
exitOnFail: false,
506+
exitOnEmpty: false,
506507
useSuiteName: false,
507508
previousResultsMax: 0,
508509
metricsReportsMax: 0,

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ inputs:
154154
description: 'Exit the workflow with a failure status if any tests fail.'
155155
required: false
156156
default: false
157+
exit-on-empty:
158+
description:
159+
'Exit the workflow with a failure status if no tests are found.'
160+
required: false
161+
default: false
157162
use-suite-name:
158163
description: 'Prefix test names with the suite name for better grouping.'
159164
required: false

community-reports/cobra-report/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Then, add it to your workflow file as follows:
2222
with:
2323
report-path: './ctrf/*.json'
2424
community-report: true
25-
communty-report-name: cobra-report
25+
community-report-name: cobra-report
2626
if: always()
2727
```
2828

dist/index.js

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

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/action-handler.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
process.env.RUN_MODE = 'action'
22

3-
import { exitActionOnFail, getAllGitHubContext, handleError } from '../github'
3+
import {
4+
exitActionOnFail,
5+
exitActionOnEmpty,
6+
getAllGitHubContext,
7+
handleError
8+
} from '../github'
49
import { getInputs } from './inputs'
510
import { prepareReport } from '../ctrf'
611
import { handleViewsAndComments, handleAnnotations } from '../github/handler'
@@ -17,6 +22,9 @@ export async function runAction(): Promise<void> {
1722
await handleViewsAndComments(inputs, report)
1823
handleAnnotations(inputs, report)
1924

25+
if (inputs.exitOnEmpty) {
26+
exitActionOnEmpty(report)
27+
}
2028
if (inputs.exitOnFail) {
2129
exitActionOnFail(report)
2230
}

src/core/cli.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ process.env.RUN_MODE = 'cli'
33

44
import yargs from 'yargs/yargs'
55
import { hideBin } from 'yargs/helpers'
6-
import { exitActionOnFail, getAllGitHubContext, handleError } from '../github'
6+
import {
7+
exitActionOnFail,
8+
exitActionOnEmpty,
9+
getAllGitHubContext,
10+
handleError
11+
} from '../github'
712
import { prepareReport } from '../ctrf'
813
import { handleViewsAndComments, handleAnnotations } from '../github/handler'
914
import { getCliInputs } from '../core/inputs'
@@ -39,6 +44,7 @@ export interface Arguments {
3944
results?: number
4045
exitOnNoFiles?: boolean
4146
exitOnFail?: boolean
47+
exitOnEmpty?: boolean
4248
fetchPreviousResults?: boolean
4349
reportOrder?: string
4450
maxWorkflowRunsToCheck?: number
@@ -327,6 +333,11 @@ async function main(): Promise<void> {
327333
description: 'Fail action when if tests fail',
328334
default: false
329335
})
336+
.options('exit-on-empty', {
337+
type: 'boolean',
338+
description: 'Fail action when if no tests are found',
339+
default: false
340+
})
330341
.options('update-comment', {
331342
type: 'boolean',
332343
description: 'Updates existing Pull Request comment',
@@ -385,6 +396,9 @@ async function main(): Promise<void> {
385396

386397
await processPrComment(argv, report, inputs)
387398

399+
if (inputs.exitOnEmpty) {
400+
exitActionOnEmpty(report)
401+
}
388402
if (inputs.exitOnFail) {
389403
exitActionOnFail(report)
390404
}

src/core/inputs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function getCliInputs(args: Arguments): Inputs {
4646
onFailOnly: args.onFailOnly || false,
4747
exitOnNoFiles: args.exitOnNoFiles || false,
4848
exitOnFail: args.exitOnFail || false,
49+
exitOnEmpty: args.exitOnEmpty || false,
4950
useSuiteName: args.useSuiteName || false,
5051
previousResultsMax: args.rows || 10,
5152
metricsReportsMax: args.results || 100,
@@ -133,6 +134,7 @@ export function getInputs(): Inputs {
133134
onFailOnly: core.getInput('on-fail-only').toLowerCase() === 'true',
134135
exitOnNoFiles: core.getInput('exit-on-no-files').toLowerCase() === 'true',
135136
exitOnFail: core.getInput('exit-on-fail').toLowerCase() === 'true',
137+
exitOnEmpty: core.getInput('exit-on-empty').toLowerCase() === 'true',
136138
useSuiteName: core.getInput('use-suite-name').toLowerCase() === 'true',
137139
previousResultsMax: parseInt(
138140
core.getInput('previous-results-max') || '10',

src/github/core.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,19 @@ export function exitActionOnFail(report: Report): void {
396396
}
397397
}
398398

399+
/**
400+
* Exits the GitHub Action with a failure status if the CTRF report does not contains any tests.
401+
*
402+
* @param report - The CTRF report containing the summary of test results.
403+
*/
404+
export function exitActionOnEmpty(report: Report): void {
405+
if (report.results.summary.tests === 0) {
406+
core.setFailed(
407+
`Github Test Reporter: ${report.results.summary.tests} tests found in the report, exiting as per configuration`
408+
)
409+
}
410+
}
411+
399412
/**
400413
* Handles errors that occur during the action, setting the GitHub Action status to failed.
401414
*

0 commit comments

Comments
 (0)