Skip to content

Commit 604ab0d

Browse files
authored
Merge pull request #1298 from mikepenz/feature/ungrouped_report
Add ability to ungroup tests by their report files
2 parents a451de5 + afbdf3d commit 604ab0d

File tree

10 files changed

+140
-14
lines changed

10 files changed

+140
-14
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ jobs:
5757
comment: true
5858
annotate_only: ${{ github.event_name == 'workflow_dispatch' }}
5959

60+
- name: Test Ungrouped test import
61+
uses: ./
62+
with:
63+
check_name: Example Ungrouped Test Report
64+
report_paths: test_results/multiple/*.xml
65+
verbose_summary: false
66+
include_passed: true
67+
detailed_summary: false
68+
group_reports: false
69+
comment: true
70+
6071
- name: Test JUnit flaky test import
6172
uses: ./
6273
with:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7777
| `report_paths` | Optional. [Glob](https://github.com/actions/toolkit/tree/master/packages/glob) expression to junit report paths. Defaults to: `**/junit-reports/TEST-*.xml`. |
7878
| `token` | Optional. GitHub token for creating a check run. Set to `${{ github.token }}` by default. |
79+
| `group_reports` | Optional. Defines if different reports found by a single `report_paths` glob expression are grouped together. Defaults to `true`. |
7980
| `test_files_prefix` | Optional. Prepends the provided prefix to test file paths within the report when annotating on GitHub. |
8081
| `exclude_sources` | Optional. Provide `,` seperated array of folders to ignore for source lookup. Defaults to: `/build/,/__pycache__/` |
8182
| `check_name` | Optional. Check name to use when creating a check run. The default is `JUnit Test Report`. |

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inputs:
1515
description: 'Xml report paths in glob format'
1616
required: false
1717
default: '**/junit-reports/TEST-*.xml'
18+
group_reports:
19+
description: 'Defines if reports are grouped into a combined test result. This '
20+
required: false
21+
default: 'true'
1822
test_files_prefix:
1923
description: 'Prefix to add to test file paths from report files when annotating'
2024
required: false

dist/index.js

Lines changed: 46 additions & 6 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/main.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export async function run(): Promise<void> {
1717
return
1818
}
1919

20+
const groupReports = core.getInput('group_reports') === 'true'
2021
const annotateOnly = core.getInput('annotate_only') === 'true'
2122
const updateCheck = core.getInput('update_check') === 'true'
2223
const checkAnnotations = core.getInput('check_annotations') === 'true'
@@ -103,7 +104,25 @@ export async function run(): Promise<void> {
103104
mergedResult.failed += testResult.failed
104105
mergedResult.passed += testResult.passed
105106
mergedResult.retried += testResult.retried
106-
testResults.push(testResult)
107+
108+
if (groupReports) {
109+
testResults.push(testResult)
110+
} else {
111+
for (const actualTestResult of testResult.testResults) {
112+
testResults.push({
113+
checkName: `${testResult.checkName} | ${actualTestResult.name}`,
114+
summary: testResult.summary,
115+
totalCount: actualTestResult.totalCount,
116+
skipped: actualTestResult.skippedCount,
117+
failed: actualTestResult.failedCount,
118+
passed: actualTestResult.passedCount,
119+
retried: actualTestResult.retriedCount,
120+
foundFiles: 1,
121+
globalAnnotations: actualTestResult.annotations,
122+
testResults: actualTestResult.testResults
123+
})
124+
}
125+
}
107126
}
108127

109128
core.setOutput('total', mergedResult.totalCount)

src/testParser.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export interface ActualTestResult {
99
name: string
1010
totalCount: number
1111
skippedCount: number
12+
failedCount: number
13+
passedCount: number
1214
retriedCount: number
1315
annotations: Annotation[]
1416
globalAnnotations: Annotation[]
@@ -18,6 +20,8 @@ export interface ActualTestResult {
1820
interface TestCasesResult {
1921
totalCount: number
2022
skippedCount: number
23+
failedCount: number
24+
passedCount: number
2125
retriedCount: number
2226
annotations: Annotation[]
2327
}
@@ -222,7 +226,7 @@ export async function parseFile(
222226
return undefined
223227
}
224228

225-
return await parseSuite(
229+
const testResult = await parseSuite(
226230
testsuite,
227231
suiteRegex, // no-op
228232
'',
@@ -240,6 +244,12 @@ export async function parseFile(
240244
globalAnnotations,
241245
resolveIgnoreClassname
242246
)
247+
248+
if (testResult !== undefined && !testResult.name) {
249+
testResult.name = pathHelper.basename(file)
250+
}
251+
252+
return testResult
243253
}
244254

245255
function templateVar(varName: string): string {
@@ -277,6 +287,8 @@ async function parseSuite(
277287

278288
let totalCount = 0
279289
let skippedCount = 0
290+
let failedCount = 0
291+
let passedCount = 0
280292
let retriedCount = 0
281293
const annotations: Annotation[] = []
282294

@@ -308,6 +320,8 @@ async function parseSuite(
308320
// expand global annotations array
309321
totalCount += parsedTestCases.totalCount
310322
skippedCount += parsedTestCases.skippedCount
323+
failedCount += parsedTestCases.failedCount
324+
passedCount += parsedTestCases.passedCount
311325
retriedCount += parsedTestCases.retriedCount
312326
annotations.push(...parsedTestCases.annotations)
313327
globalAnnotations.push(...parsedTestCases.annotations)
@@ -318,6 +332,8 @@ async function parseSuite(
318332
name: suiteName,
319333
totalCount,
320334
skippedCount,
335+
failedCount,
336+
passedCount,
321337
retriedCount,
322338
annotations,
323339
globalAnnotations,
@@ -360,6 +376,8 @@ async function parseSuite(
360376
childSuiteResults.push(childSuiteResult)
361377
totalCount += childSuiteResult.totalCount
362378
skippedCount += childSuiteResult.skippedCount
379+
failedCount += childSuiteResult.failedCount
380+
passedCount += childSuiteResult.passedCount
363381
retriedCount += childSuiteResult.retriedCount
364382
}
365383

@@ -369,6 +387,8 @@ async function parseSuite(
369387
name: suiteName,
370388
totalCount,
371389
skippedCount,
390+
failedCount,
391+
passedCount,
372392
retriedCount,
373393
annotations,
374394
globalAnnotations,
@@ -381,6 +401,8 @@ async function parseSuite(
381401
name: suiteName,
382402
totalCount,
383403
skippedCount,
404+
failedCount,
405+
passedCount,
384406
retriedCount,
385407
annotations,
386408
globalAnnotations,
@@ -576,9 +598,13 @@ async function parseTestCases(
576598
if (limit >= 0 && annotations.length >= limit) break
577599
}
578600

601+
const failedCount = annotations.filter(a => a.annotation_level === 'failure').length
602+
const passedCount = totalCount - failedCount - skippedCount
579603
return {
580604
totalCount,
581605
skippedCount,
606+
failedCount,
607+
passedCount,
582608
retriedCount,
583609
annotations
584610
}
@@ -616,6 +642,8 @@ export async function parseTestReports(
616642
const testResults: ActualTestResult[] = []
617643
let totalCount = 0
618644
let skipped = 0
645+
let failed = 0
646+
let passed = 0
619647
let retried = 0
620648
let foundFiles = 0
621649
for await (const file of globber.globGenerator()) {
@@ -642,9 +670,11 @@ export async function parseTestReports(
642670
)
643671

644672
if (!testResult) continue
645-
const {totalCount: c, skippedCount: s, retriedCount: r} = testResult
673+
const {totalCount: c, skippedCount: s, failedCount: f, passedCount: p, retriedCount: r} = testResult
646674
totalCount += c
647675
skipped += s
676+
failed += f
677+
passed += p
648678
retried += r
649679
testResults.push(testResult)
650680

@@ -653,10 +683,6 @@ export async function parseTestReports(
653683
}
654684
}
655685

656-
// get the count of passed and failed tests.
657-
const failed = globalAnnotations.filter(a => a.annotation_level === 'failure').length
658-
const passed = totalCount - failed - skipped
659-
660686
return {
661687
checkName,
662688
summary,

test_results/multiple/test_10.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<testsuites failures="0" tests="8" time="1967986371">
2+
<testsuite>
3+
<testcase name="Command Test: apt-get upgrade" time="999638317"></testcase>
4+
<testcase name="File Existence Test: /home/app/app" time="0"></testcase>
5+
<testcase name="Metadata Test" time="0"></testcase>
6+
</testsuite>
7+
</testsuites>

test_results/multiple/test_11.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<testsuites failures="0" tests="8" time="1967986371">
2+
<testsuite>
3+
<testcase name="Command Test: apt-get upgrade" time="999638317"></testcase>
4+
<testcase name="File Existence Test: /home/app/app" time="0"></testcase>
5+
<testcase name="Metadata Test" time="0">
6+
<failure message="AssertionError: assert">SackTrace</failure>
7+
</testcase>
8+
</testsuite>
9+
</testsuites>

test_results/multiple/test_12.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<testsuites failures="0" tests="8" time="1967986371">
2+
<testsuite>
3+
<testcase name="Command Test: apt-get upgrade" time="999638317"></testcase>
4+
<testcase name="File Existence Test: /home/app/app" time="0">
5+
<skipped></skipped>
6+
</testcase>
7+
<testcase name="Metadata Test" time="0"></testcase>
8+
</testsuite>
9+
</testsuites>

0 commit comments

Comments
 (0)