Skip to content

Commit f228c54

Browse files
committed
- add ability to skip successful summaries
- FIXES #1287
1 parent c96c1ea commit f228c54

File tree

8 files changed

+61
-13
lines changed

8 files changed

+61
-13
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ jobs:
9494
| `annotate_only` | Optional. Will only annotate the results on the files, won't create a check run. Defaults to `false`. |
9595
| `transformers` | Optional. Array of `Transformer`s offering the ability to adjust the fileName. Defaults to: `[{"searchValue":"::","replaceValue":"/"}]` |
9696
| `job_summary` | Optional. Enables the publishing of the job summary for the results. Defaults to `true`. May be required to disable [Enterprise Server](https://github.com/mikepenz/action-junit-report/issues/637) |
97-
| `detailed_summary` | Optional. Include table with all test results in the summary. Defaults to `false`. |
98-
| `flaky_summary` | Optional. Include table with all flaky results in the summary. Defaults to `false`. |
99-
| `verbose_summary` | Optional. Detail table will note if there were no test annotations for a test suite. Defaults to `true`. |
97+
| `detailed_summary` | Optional. Include table with all test results in the summary (Also applies to comment). Defaults to `false`. |
98+
| `flaky_summary` | Optional. Include table with all flaky results in the summary (Also applies to comment). Defaults to `false`. |
99+
| `verbose_summary` | Optional. Detail table will note if there were no test annotations for a test suite (Also applies to comment). Defaults to `true`. |
100+
| `skip_success_summary` | Optional. Skips the summary table if only successful tests were detected (Also applies to comment). Defaults to `true`. |
100101
| `group_suite` | Optional. If enabled, will group the testcases by test suite in the `detailed_summary`. Defaults to `false`. |
101102
| `comment` | Optional. Enables a comment being added to the PR with the summary tables (Respects the summary configuration flags). Defaults to `false`. |
102103
| `updateComment` | Optional. If a prior action run comment exists, it is updated. If disabled, new comments are creted for each run. Defaults to `true`. |
@@ -150,7 +151,6 @@ you can increase the memory allocation by setting an environment variable
150151
</p>
151152
</details>
152153

153-
154154
### Action outputs
155155

156156
After action execution it will return the test counts as output.
@@ -280,8 +280,6 @@ This will selectively use different methods for forked and unforked repos.
280280
</p>
281281
</details>
282282

283-
284-
285283
## Sample 🖥️
286284

287285
<div align="center">

__tests__/table.test.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ describe('buildSummaryTables', () => {
5959
'/'
6060
)
6161

62-
const [table, detailTable, flakyTable] = buildSummaryTables([testResult], true, true, true, true)
62+
const [table, detailTable, flakyTable] = buildSummaryTables([testResult], true, true, true, true, false)
6363

6464
expect(table).toStrictEqual(NORMAL_TABLE)
6565
expect(detailTable).toStrictEqual([
@@ -86,7 +86,7 @@ describe('buildSummaryTables', () => {
8686
expect(flakyTable).toStrictEqual(FLAKY_TABLE)
8787
})
8888

89-
it('should group detail tables', async () => {
89+
it('should skip only successful tables', async () => {
9090
const testResult = await parseTestReports(
9191
'checkName',
9292
'summary',
@@ -101,6 +101,26 @@ describe('buildSummaryTables', () => {
101101
)
102102

103103
const [table, detailTable, flakyTable] = buildSummaryTables([testResult], true, true, true, true, true)
104+
expect(table).toStrictEqual([])
105+
expect(detailTable).toStrictEqual([])
106+
expect(flakyTable).toStrictEqual([])
107+
})
108+
109+
it('should group detail tables', async () => {
110+
const testResult = await parseTestReports(
111+
'checkName',
112+
'summary',
113+
'test_results/nested/multi-level.xml',
114+
'*',
115+
true,
116+
true,
117+
true,
118+
[],
119+
'{{SUITE_NAME}}/{{TEST_NAME}}',
120+
'/'
121+
)
122+
123+
const [table, detailTable, flakyTable] = buildSummaryTables([testResult], true, true, true, true, false, true)
104124

105125
expect(table).toStrictEqual(NORMAL_TABLE)
106126
expect(detailTable).toStrictEqual([

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ inputs:
9898
description: 'Include note of missing test annotations in summary.'
9999
required: false
100100
default: 'true'
101+
skip_success_summary:
102+
description: 'Skips summaries that would not contain failed tests'
103+
required: false
104+
default: 'false'
101105
group_suite:
102106
description: 'If enabled, will group the testcases by test suite in the `detailed_summary`'
103107
required: false

dist/index.js

Lines changed: 14 additions & 3 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/annotator.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export async function attachSummary(
131131
detailsTable: SummaryTableRow[],
132132
flakySummary: SummaryTableRow[]
133133
): Promise<void> {
134-
await core.summary.addTable(table).write()
134+
if (table.length > 0) {
135+
await core.summary.addTable(table).write()
136+
}
135137
if (detailsTable.length > 1) {
136138
await core.summary.addTable(detailsTable).write()
137139
}
@@ -157,6 +159,11 @@ export async function attachComment(
157159
return
158160
}
159161

162+
if (table.length === 0 && detailsTable.length === 0 && flakySummary.length === 0) {
163+
core.debug(`Tables for comment were empty. 'skip_success_summary' enabled?`)
164+
return
165+
}
166+
160167
const identifier = buildCommentIdentifier(checkName)
161168

162169
let comment = buildTable(table)

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export async function run(): Promise<void> {
3232
const detailedSummary = core.getInput('detailed_summary') === 'true'
3333
const flakySummary = core.getInput('flaky_summary') === 'true'
3434
const verboseSummary = core.getInput('verbose_summary') === 'true'
35+
const skipSuccessSummary = core.getInput('skip_success_summary') === 'true'
3536
const groupSuite = core.getInput('group_suite') === 'true'
3637
const comment = core.getInput('comment') === 'true'
3738
const updateComment = core.getInput('updateComment') === 'true'
@@ -157,6 +158,7 @@ export async function run(): Promise<void> {
157158
detailedSummary,
158159
flakySummary,
159160
verboseSummary,
161+
skipSuccessSummary,
160162
groupSuite
161163
)
162164
if (jobSummary && supportsJobSummary) {

src/table.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function buildSummaryTables(
99
detailedSummary: boolean,
1010
flakySummary: boolean,
1111
verboseSummary: boolean,
12+
skipSuccessSummary: boolean,
1213
groupSuite = false
1314
): [SummaryTableRow[], SummaryTableRow[], SummaryTableRow[]] {
1415
// only include a warning icon if there are skipped tests
@@ -17,6 +18,11 @@ export function buildSummaryTables(
1718
const hasFailed = testResults.some(testResult => testResult.failed > 0)
1819
const hasTests = testResults.some(testResult => testResult.totalCount > 0)
1920

21+
if (skipSuccessSummary && !hasFailed) {
22+
// if we have skip success summary enabled, and we don't have any test failures, return empty tables
23+
return [[], [], []]
24+
}
25+
2026
const passedHeader = hasTests ? (hasPassed ? (hasFailed ? 'Passed ☑️' : 'Passed ✅') : 'Passed') : 'Passed ❌️'
2127
const skippedHeader = hasSkipped ? 'Skipped ⚠️' : 'Skipped'
2228
const failedHeader = hasFailed ? 'Failed ❌️' : 'Failed'

0 commit comments

Comments
 (0)