Skip to content

Commit

Permalink
- add ability to skip successful summaries
Browse files Browse the repository at this point in the history
  - FIXES #1287
  • Loading branch information
mikepenz committed Jan 26, 2025
1 parent c96c1ea commit f228c54
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 13 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ jobs:
| `annotate_only` | Optional. Will only annotate the results on the files, won't create a check run. Defaults to `false`. |
| `transformers` | Optional. Array of `Transformer`s offering the ability to adjust the fileName. Defaults to: `[{"searchValue":"::","replaceValue":"/"}]` |
| `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) |
| `detailed_summary` | Optional. Include table with all test results in the summary. Defaults to `false`. |
| `flaky_summary` | Optional. Include table with all flaky results in the summary. Defaults to `false`. |
| `verbose_summary` | Optional. Detail table will note if there were no test annotations for a test suite. Defaults to `true`. |
| `detailed_summary` | Optional. Include table with all test results in the summary (Also applies to comment). Defaults to `false`. |
| `flaky_summary` | Optional. Include table with all flaky results in the summary (Also applies to comment). Defaults to `false`. |
| `verbose_summary` | Optional. Detail table will note if there were no test annotations for a test suite (Also applies to comment). Defaults to `true`. |
| `skip_success_summary` | Optional. Skips the summary table if only successful tests were detected (Also applies to comment). Defaults to `true`. |
| `group_suite` | Optional. If enabled, will group the testcases by test suite in the `detailed_summary`. Defaults to `false`. |
| `comment` | Optional. Enables a comment being added to the PR with the summary tables (Respects the summary configuration flags). Defaults to `false`. |
| `updateComment` | Optional. If a prior action run comment exists, it is updated. If disabled, new comments are creted for each run. Defaults to `true`. |
Expand Down Expand Up @@ -150,7 +151,6 @@ you can increase the memory allocation by setting an environment variable
</p>
</details>


### Action outputs

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



## Sample 🖥️

<div align="center">
Expand Down
24 changes: 22 additions & 2 deletions __tests__/table.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('buildSummaryTables', () => {
'/'
)

const [table, detailTable, flakyTable] = buildSummaryTables([testResult], true, true, true, true)
const [table, detailTable, flakyTable] = buildSummaryTables([testResult], true, true, true, true, false)

expect(table).toStrictEqual(NORMAL_TABLE)
expect(detailTable).toStrictEqual([
Expand All @@ -86,7 +86,7 @@ describe('buildSummaryTables', () => {
expect(flakyTable).toStrictEqual(FLAKY_TABLE)
})

it('should group detail tables', async () => {
it('should skip only successful tables', async () => {
const testResult = await parseTestReports(
'checkName',
'summary',
Expand All @@ -101,6 +101,26 @@ describe('buildSummaryTables', () => {
)

const [table, detailTable, flakyTable] = buildSummaryTables([testResult], true, true, true, true, true)
expect(table).toStrictEqual([])
expect(detailTable).toStrictEqual([])
expect(flakyTable).toStrictEqual([])
})

it('should group detail tables', async () => {
const testResult = await parseTestReports(
'checkName',
'summary',
'test_results/nested/multi-level.xml',
'*',
true,
true,
true,
[],
'{{SUITE_NAME}}/{{TEST_NAME}}',
'/'
)

const [table, detailTable, flakyTable] = buildSummaryTables([testResult], true, true, true, true, false, true)

expect(table).toStrictEqual(NORMAL_TABLE)
expect(detailTable).toStrictEqual([
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ inputs:
description: 'Include note of missing test annotations in summary.'
required: false
default: 'true'
skip_success_summary:
description: 'Skips summaries that would not contain failed tests'
required: false
default: 'false'
group_suite:
description: 'If enabled, will group the testcases by test suite in the `detailed_summary`'
required: false
Expand Down
17 changes: 14 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion src/annotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export async function attachSummary(
detailsTable: SummaryTableRow[],
flakySummary: SummaryTableRow[]
): Promise<void> {
await core.summary.addTable(table).write()
if (table.length > 0) {
await core.summary.addTable(table).write()
}
if (detailsTable.length > 1) {
await core.summary.addTable(detailsTable).write()
}
Expand All @@ -157,6 +159,11 @@ export async function attachComment(
return
}

if (table.length === 0 && detailsTable.length === 0 && flakySummary.length === 0) {
core.debug(`Tables for comment were empty. 'skip_success_summary' enabled?`)
return
}

const identifier = buildCommentIdentifier(checkName)

let comment = buildTable(table)
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export async function run(): Promise<void> {
const detailedSummary = core.getInput('detailed_summary') === 'true'
const flakySummary = core.getInput('flaky_summary') === 'true'
const verboseSummary = core.getInput('verbose_summary') === 'true'
const skipSuccessSummary = core.getInput('skip_success_summary') === 'true'
const groupSuite = core.getInput('group_suite') === 'true'
const comment = core.getInput('comment') === 'true'
const updateComment = core.getInput('updateComment') === 'true'
Expand Down Expand Up @@ -157,6 +158,7 @@ export async function run(): Promise<void> {
detailedSummary,
flakySummary,
verboseSummary,
skipSuccessSummary,
groupSuite
)
if (jobSummary && supportsJobSummary) {
Expand Down
6 changes: 6 additions & 0 deletions src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function buildSummaryTables(
detailedSummary: boolean,
flakySummary: boolean,
verboseSummary: boolean,
skipSuccessSummary: boolean,
groupSuite = false
): [SummaryTableRow[], SummaryTableRow[], SummaryTableRow[]] {
// only include a warning icon if there are skipped tests
Expand All @@ -17,6 +18,11 @@ export function buildSummaryTables(
const hasFailed = testResults.some(testResult => testResult.failed > 0)
const hasTests = testResults.some(testResult => testResult.totalCount > 0)

if (skipSuccessSummary && !hasFailed) {
// if we have skip success summary enabled, and we don't have any test failures, return empty tables
return [[], [], []]
}

const passedHeader = hasTests ? (hasPassed ? (hasFailed ? 'Passed ☑️' : 'Passed ✅') : 'Passed') : 'Passed ❌️'
const skippedHeader = hasSkipped ? 'Skipped ⚠️' : 'Skipped'
const failedHeader = hasFailed ? 'Failed ❌️' : 'Failed'
Expand Down

0 comments on commit f228c54

Please sign in to comment.