mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Add option of use-actions-summary
This commit is contained in:
parent
bd77050543
commit
3608ee03fd
17 changed files with 4236 additions and 402 deletions
93
src/main.ts
93
src/main.ts
|
|
@ -8,6 +8,7 @@ import {LocalFileProvider} from './input-providers/local-file-provider'
|
|||
import {FileContent} from './input-providers/input-provider'
|
||||
import {ParseOptions, TestParser} from './test-parser'
|
||||
import {TestRunResult} from './test-results'
|
||||
import {getAnnotations} from './report/get-annotations'
|
||||
import {getReport} from './report/get-report'
|
||||
|
||||
import {DartJsonParser} from './parsers/dart-json/dart-json-parser'
|
||||
|
|
@ -18,6 +19,7 @@ import {MochaJsonParser} from './parsers/mocha-json/mocha-json-parser'
|
|||
|
||||
import {normalizeDirPath, normalizeFilePath} from './utils/path-utils'
|
||||
import {getCheckRunContext} from './utils/github-utils'
|
||||
import {Icon} from './utils/markdown-utils'
|
||||
|
||||
async function main(): Promise<void> {
|
||||
try {
|
||||
|
|
@ -41,6 +43,7 @@ class TestReporter {
|
|||
readonly failOnError = core.getInput('fail-on-error', {required: true}) === 'true'
|
||||
readonly workDirInput = core.getInput('working-directory', {required: false})
|
||||
readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true'
|
||||
readonly useActionsSummary = core.getInput('use-actions-summary', {required: false}) === 'true'
|
||||
readonly badgeTitle = core.getInput('badge-title', {required: false})
|
||||
readonly token = core.getInput('token', {required: true})
|
||||
readonly octokit: InstanceType<typeof GitHub>
|
||||
|
|
@ -154,50 +157,60 @@ class TestReporter {
|
|||
results.push(tr)
|
||||
}
|
||||
|
||||
// core.info(`Creating check run ${name}`)
|
||||
// const createResp = await this.octokit.checks.create({
|
||||
// head_sha: this.context.sha,
|
||||
// name,
|
||||
// status: 'in_progress',
|
||||
// output: {
|
||||
// title: name,
|
||||
// summary: ''
|
||||
// },
|
||||
// ...github.context.repo
|
||||
// })
|
||||
|
||||
core.info('Creating report summary')
|
||||
const {listSuites, listTests, onlySummary, badgeTitle} = this
|
||||
const baseUrl = ''
|
||||
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary, badgeTitle})
|
||||
core.info('Summary content:')
|
||||
core.info(summary)
|
||||
await fs.promises.writeFile(this.path.replace('*.trx', 'test-summary.md'), summary)
|
||||
core.info('File content:')
|
||||
core.info(fs.readFileSync(this.path.replace('*.trx', 'test-summary.md'), 'utf8'))
|
||||
const {listSuites, listTests, onlySummary, useActionsSummary, badgeTitle} = this
|
||||
let baseUrl = ''
|
||||
let checkRunId = 0
|
||||
if (!this.useActionsSummary) {
|
||||
core.info(`Creating check run ${name}`)
|
||||
const createResp = await this.octokit.rest.checks.create({
|
||||
head_sha: this.context.sha,
|
||||
name,
|
||||
status: 'in_progress',
|
||||
output: {
|
||||
title: name,
|
||||
summary: ''
|
||||
},
|
||||
...github.context.repo
|
||||
})
|
||||
baseUrl = createResp.data.html_url as string
|
||||
checkRunId = createResp.data.id
|
||||
}
|
||||
|
||||
// core.info('Creating annotations')
|
||||
// const annotations = getAnnotations(results, this.maxAnnotations)
|
||||
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary, useActionsSummary, badgeTitle})
|
||||
|
||||
// const isFailed = results.some(tr => tr.result === 'failed')
|
||||
// const conclusion = isFailed ? 'failure' : 'success'
|
||||
// const icon = isFailed ? Icon.fail : Icon.success
|
||||
if (this.useActionsSummary) {
|
||||
core.info('Summary content:')
|
||||
core.info(summary)
|
||||
await fs.promises.writeFile(this.path.replace('*.trx', 'test-summary.md'), summary)
|
||||
core.info('File content:')
|
||||
core.info(fs.readFileSync(this.path.replace('*.trx', 'test-summary.md'), 'utf8'))
|
||||
}
|
||||
|
||||
// core.info(`Updating check run conclusion (${conclusion}) and output`)
|
||||
// const resp = await this.octokit.checks.update({
|
||||
// check_run_id: createResp.data.id,
|
||||
// conclusion,
|
||||
// status: 'completed',
|
||||
// output: {
|
||||
// title: `${name} ${icon}`,
|
||||
// summary,
|
||||
// annotations
|
||||
// },
|
||||
// ...github.context.repo
|
||||
// })
|
||||
// core.info(`Check run create response: ${resp.status}`)
|
||||
// core.info(`Check run URL: ${resp.data.url}`)
|
||||
// core.info(`Check run HTML: ${resp.data.html_url}`)
|
||||
if (!this.useActionsSummary) {
|
||||
core.info('Creating annotations')
|
||||
const annotations = getAnnotations(results, this.maxAnnotations)
|
||||
|
||||
const isFailed = results.some(tr => tr.result === 'failed')
|
||||
const conclusion = isFailed ? 'failure' : 'success'
|
||||
const icon = isFailed ? Icon.fail : Icon.success
|
||||
|
||||
core.info(`Updating check run conclusion (${conclusion}) and output`)
|
||||
const resp = await this.octokit.rest.checks.update({
|
||||
check_run_id: checkRunId,
|
||||
conclusion,
|
||||
status: 'completed',
|
||||
output: {
|
||||
title: `${name} ${icon}`,
|
||||
summary,
|
||||
annotations
|
||||
},
|
||||
...github.context.repo
|
||||
})
|
||||
core.info(`Check run create response: ${resp.status}`)
|
||||
core.info(`Check run URL: ${resp.data.url}`)
|
||||
core.info(`Check run HTML: ${resp.data.html_url}`)
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export enum Align {
|
|||
}
|
||||
|
||||
export const Icon = {
|
||||
skip: ':no_entry_sign:',
|
||||
skip: ':warning:',
|
||||
success: ':white_check_mark:',
|
||||
fail: ':x:'
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue