Skip to content

Commit bb6b54d

Browse files
feat: enhance report output handling in GitHub Actions (#161)
1 parent 0f9b46a commit bb6b54d

File tree

5 files changed

+99
-5
lines changed

5 files changed

+99
-5
lines changed

badges/coverage.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index.js

Lines changed: 62 additions & 1 deletion
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/github/handler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { CtrfReport, Inputs } from '../types'
99
import { generateViews, annotateFailed } from './core'
1010
import { components } from '@octokit/openapi-types'
1111
import { createCheckRun } from '../client/github/checks'
12+
import { checkReportSize } from '../utils/report-utils'
1213

1314
type IssueComment = components['schemas']['issue-comment']
1415
const UPDATE_EMOJI = '🔄'
@@ -36,7 +37,11 @@ export async function handleViewsAndComments(
3637
generateViews(inputs, report)
3738

3839
core.setOutput('summary', core.summary.stringify())
39-
core.setOutput('report', JSON.stringify(report))
40+
41+
const { reportJson, isSafeToOutput } = checkReportSize(report, 'report')
42+
if (isSafeToOutput) {
43+
core.setOutput('report', reportJson)
44+
}
4045

4146
if (shouldAddCommentToPullRequest(inputs, report)) {
4247
await postOrUpdatePRComment(inputs, INVISIBLE_MARKER)

src/utils/report-utils.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Inputs } from '../types'
1+
import { Inputs, CtrfReport } from '../types'
2+
import * as core from '@actions/core'
23

34
/**
45
* Converts a kebab-case report type (e.g., 'summary-report') to camelCase input property (e.g., 'summaryReport')
@@ -63,3 +64,30 @@ function isInputKey(key: string): key is keyof Inputs {
6364

6465
return validInputKeys.includes(key as keyof Inputs)
6566
}
67+
68+
/**
69+
* Checks if a CTRF report is within GitHub Actions output size limits and logs appropriate messages
70+
*
71+
* @param report - The CTRF report to check
72+
* @param outputName - The name of the output (for logging purposes)
73+
* @returns An object containing the JSON string and whether it's safe to output
74+
*/
75+
export function checkReportSize(
76+
report: CtrfReport,
77+
outputName = 'report'
78+
): { reportJson: string; isSafeToOutput: boolean } {
79+
const reportJson = JSON.stringify(report)
80+
const reportSizeBytes = Buffer.byteLength(reportJson, 'utf8')
81+
const reportSizeMB = (reportSizeBytes / (1024 * 1024)).toFixed(2)
82+
83+
if (reportSizeBytes > 1000000) {
84+
// 1MB limit
85+
core.warning(
86+
`${outputName} is ${reportSizeMB}MB, which exceeds GitHub's 1MB output limit. ` +
87+
`Skipping ${outputName} output. Consider using write-ctrf-to-file instead.`
88+
)
89+
return { reportJson, isSafeToOutput: false }
90+
} else {
91+
return { reportJson, isSafeToOutput: true }
92+
}
93+
}

0 commit comments

Comments
 (0)