Skip to content

Commit 9e39d10

Browse files
author
Sascha Nowak
committed
Generate seperated files for summary and details
Prevent error with github.qkg1.topment limit of 65536 characters
1 parent a20ebb2 commit 9e39d10

10 files changed

Lines changed: 91 additions & 62 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@ Thumbs.db
9797
# Ignore built ts files
9898
__tests__/runner/*
9999
lib/**/*
100-
code-coverage-results.md
100+
code-coverage-*.md
101+
!__tests__/data/code-coverage-*.md
102+

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ A path to the code coverage file to analyse. Also supports using glob patterns t
2020
## Outputs
2121

2222

23-
### Markdown Example
23+
### Markdown Example Summary
2424

2525
<table>
2626
<tr>
@@ -50,6 +50,9 @@ A path to the code coverage file to analyse. Also supports using glob patterns t
5050
<td align="right"><strong>31/33
5151
<td align="center"><strong>✅
5252
</table>
53+
54+
### Markdown Example Details
55+
5356
<details>
5457
<summary>Code Coverage details</summary>
5558
<table>
@@ -114,17 +117,19 @@ with:
114117
Add the following to your workflow to include the summary in the job summary:
115118
```yaml
116119
name: 'Add Code Coverage to Job Summary'
117-
run: cat code-coverage-results-merged.md >> $GITHUB_STEP_SUMMARY
120+
run: |
121+
cat code-coverage-summary.md >> $GITHUB_STEP_SUMMARY
122+
cat code-coverage-details.md >> $GITHUB_STEP_SUMMARY
118123
```
119124
120125
Add the following to your workflow to post the summary as a Pull Request comment:
121126
```yaml
122-
name: 'Add Code Coverage as PR Comment'
127+
name: 'Add Code Coverage Summary as PR Comment'
123128
uses: marocchino/sticky-pull-request-comment@v2
124129
if: github.event_name == 'pull_request'
125130
with:
126131
recreate: true
127-
path: code-coverage-results-merged.md
132+
path: code-coverage-summary.md
128133
```
129134
130135
## Version Numbers
Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
11

2-
<table>
3-
<tr>
4-
<th colspan="8">Code Coverage
5-
<tr>
6-
<th colspan="1">Package
7-
<th colspan="2">Lines
8-
<th colspan="2">Functions
9-
<th colspan="2">Classes
10-
<th colspan="1">Health
11-
<tr>
12-
<td>nxdummy
13-
<td align="center">96.30%
14-
<td align="right">26/27
15-
<td align="center">83.33%
16-
<td align="right">5/6
17-
<td align="center">50.00%
18-
<td align="right">1/2
19-
<td align="center">✅
20-
<tr>
21-
<td><strong>Summary
22-
<td align="center"><strong>96.30%
23-
<td align="right"><strong>26/27
24-
<td align="center"><strong>83.33%
25-
<td align="right"><strong>5/6
26-
<td align="center"><strong>50.00%
27-
<td align="right"><strong>1/2
28-
<td align="center"><strong>✅
29-
</table>
302
<details>
313
<summary>Code Coverage details</summary>
324
<table>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
<table>
3+
<tr>
4+
<th colspan="8">Code Coverage
5+
<tr>
6+
<th colspan="1">Package
7+
<th colspan="2">Lines
8+
<th colspan="2">Functions
9+
<th colspan="2">Classes
10+
<th colspan="1">Health
11+
<tr>
12+
<td>nxdummy
13+
<td align="center">96.30%
14+
<td align="right">26/27
15+
<td align="center">83.33%
16+
<td align="right">5/6
17+
<td align="center">50.00%
18+
<td align="right">1/2
19+
<td align="center">✅
20+
<tr>
21+
<td><strong>Summary
22+
<td align="center"><strong>96.30%
23+
<td align="right"><strong>26/27
24+
<td align="center"><strong>83.33%
25+
<td align="right"><strong>5/6
26+
<td align="center"><strong>50.00%
27+
<td align="right"><strong>1/2
28+
<td align="center"><strong>✅
29+
</table>
30+

__tests__/main.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ test('Row metric with bold style', () => {
141141
test('Markdown generation', async () => {
142142
process.env['INPUT_FILENAME'] = './__tests__/data/clover.xml'
143143
const generated = await run()
144-
const expected = (
145-
await readFile(path.resolve('./__tests__/data/code-coverage-results.md'))
144+
const summary = (
145+
await readFile(path.resolve('./__tests__/data/code-coverage-summary.md'))
146146
).toString()
147-
expect(expected).toBe(generated)
147+
const details = (
148+
await readFile(path.resolve('./__tests__/data/code-coverage-details.md'))
149+
).toString()
150+
expect(summary).toBe(generated.summary)
151+
expect(details).toBe(generated.details)
148152
})

dist/index.js

Lines changed: 17 additions & 10 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.

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "clover-code-coverage-summary",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"private": true,
55
"description": "TypeScript template action",
66
"main": "lib/main.js",

src/main.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ export function getMetricRow(
128128
}`
129129
}
130130

131-
export async function run(): Promise<string> {
132-
const results: string[] = ['']
131+
export async function run(): Promise<{summary: string; details: string}> {
132+
const summary: string[] = ['']
133+
const details: string[] = ['']
133134

134135
try {
135136
const files = await glob(getInput('filename'), {ignore: 'node_modules/**'})
@@ -256,7 +257,7 @@ export async function run(): Promise<string> {
256257
packages[packageName].metrics.coveredclasses += covered
257258
}
258259

259-
const summary: SummaryMetric = {
260+
const summaryMetric: SummaryMetric = {
260261
files: parseInt(reportData.coverage.project.metrics['@_files'], 10),
261262
loc: parseInt(reportData.coverage.project.metrics['@_loc'], 10),
262263
ncloc: parseInt(reportData.coverage.project.metrics['@_ncloc'], 10),
@@ -296,7 +297,7 @@ export async function run(): Promise<string> {
296297
)
297298
}
298299

299-
results.push(`<table>
300+
summary.push(`<table>
300301
<tr>
301302
<th colspan="8">Code Coverage
302303
<tr>
@@ -308,10 +309,12 @@ export async function run(): Promise<string> {
308309
${Object.values(packages)
309310
.map(_package => getMetricRow(_package.name, _package.metrics))
310311
.join('\n')}
311-
${getMetricRow('Summary', summary, true)}
312+
${getMetricRow('Summary', summaryMetric, true)}
312313
</table>`)
314+
summary.push('')
315+
summary.push('')
313316

314-
results.push(`<details>
317+
details.push(`<details>
315318
<summary>Code Coverage details</summary>
316319
<table>
317320
<tr>
@@ -331,19 +334,25 @@ export async function run(): Promise<string> {
331334
.join('\n')}`
332335
)
333336
.join('\n')}
334-
${getMetricRow('Summary', summary, true)}
337+
${getMetricRow('Summary', summaryMetric, true)}
335338
</table>
336339
</details>`)
340+
details.push('')
341+
details.push('')
337342
}
338-
339-
results.push('')
340-
results.push('')
341343
} catch (e) {
342344
if (e instanceof Error) setFailed(e.message)
343345
}
344346

345-
await writeFile(path.resolve('code-coverage-results.md'), results.join('\n'))
346-
return results.join('\n')
347+
await writeFile(path.resolve('code-coverage-results.md'), summary.join('\n'))
348+
await writeFile(
349+
path.resolve('code-coverage-results-details.md'),
350+
details.join('\n')
351+
)
352+
return {
353+
summary: summary.join('\n'),
354+
details: details.join('\n')
355+
}
347356
}
348357

349358
run()

0 commit comments

Comments
 (0)