Add option of use-actions-summary

This commit is contained in:
Ray Xu 2022-04-24 23:03:33 +00:00 committed by Zach Renner
parent bd77050543
commit 3608ee03fd
17 changed files with 4236 additions and 402 deletions

View file

@ -6,12 +6,14 @@ import {getFirstNonEmptyLine} from '../utils/parse-utils'
import {slug} from '../utils/slugger'
const MAX_REPORT_LENGTH = 65535
const MAX_ACTIONS_SUMMARY_LENGTH = 131072 // 1048576 soon
export interface ReportOptions {
listSuites: 'all' | 'failed' | 'none'
listTests: 'all' | 'failed' | 'none'
baseUrl: string
onlySummary: boolean
useActionsSummary: boolean
badgeTitle: string
}
@ -20,6 +22,7 @@ const defaultOptions: ReportOptions = {
listTests: 'all',
baseUrl: '',
onlySummary: false,
useActionsSummary: true,
badgeTitle: 'tests'
}
@ -32,7 +35,7 @@ export function getReport(results: TestRunResult[], options: ReportOptions = def
let lines = renderReport(results, opts)
let report = lines.join('\n')
if (getByteLength(report) <= MAX_REPORT_LENGTH) {
if (getByteLength(report) <= getMaxReportLength(options)) {
return report
}
@ -41,20 +44,24 @@ export function getReport(results: TestRunResult[], options: ReportOptions = def
opts.listTests = 'failed'
lines = renderReport(results, opts)
report = lines.join('\n')
if (getByteLength(report) <= MAX_REPORT_LENGTH) {
if (getByteLength(report) <= getMaxReportLength(options)) {
return report
}
}
core.warning(`Test report summary exceeded limit of ${MAX_REPORT_LENGTH} bytes and will be trimmed`)
return trimReport(lines)
core.warning(`Test report summary exceeded limit of ${getMaxReportLength(options)} bytes and will be trimmed`)
return trimReport(lines, options)
}
function trimReport(lines: string[]): string {
function getMaxReportLength(options: ReportOptions = defaultOptions): number {
return options.useActionsSummary ? MAX_ACTIONS_SUMMARY_LENGTH : MAX_REPORT_LENGTH
}
function trimReport(lines: string[], options: ReportOptions): string {
const closingBlock = '```'
const errorMsg = `**Report exceeded GitHub limit of ${MAX_REPORT_LENGTH} bytes and has been trimmed**`
const errorMsg = `**Report exceeded GitHub limit of ${getMaxReportLength(options)} bytes and has been trimmed**`
const maxErrorMsgLength = closingBlock.length + errorMsg.length + 2
const maxReportLength = MAX_REPORT_LENGTH - maxErrorMsgLength
const maxReportLength = getMaxReportLength(options) - maxErrorMsgLength
let reportLength = 0
let codeBlock = false