1
0
Fork 0
mirror of https://github.com/dorny/test-reporter.git synced 2026-02-04 13:37:56 +01:00

Enforce Check Run API limits

This commit is contained in:
Michal Dorner 2021-01-25 10:23:49 +01:00
parent fdd3509024
commit 7af0073fa3
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
5 changed files with 49 additions and 11 deletions

View file

@ -8,7 +8,7 @@ import {parseJestJunit} from './parsers/jest-junit/jest-junit-parser'
import {FileContent, ParseOptions, ParseTestResult} from './parsers/parser-types'
import {normalizeDirPath} from './utils/file-utils'
import {listFiles} from './utils/git'
import {getCheckRunSha} from './utils/github-utils'
import {enforceCheckRunLimits, getCheckRunSha} from './utils/github-utils'
async function run(): Promise<void> {
try {
@ -19,7 +19,7 @@ async function run(): Promise<void> {
}
async function main(): Promise<void> {
const annotations = core.getInput('annotations', {required: true}) === 'true'
const maxAnnotations = parseInt(core.getInput('max-annotations', {required: true}))
const failOnError = core.getInput('fail-on-error', {required: true}) === 'true'
const name = core.getInput('name', {required: true})
const path = core.getInput('path', {required: true})
@ -27,6 +27,11 @@ async function main(): Promise<void> {
const token = core.getInput('token', {required: true})
const workDirInput = core.getInput('working-directory', {required: false})
if (isNaN(maxAnnotations) || maxAnnotations < 0 || maxAnnotations > 50) {
core.setFailed(`Input parameter 'max-annotations' has invalid value`)
return
}
if (workDirInput) {
core.info(`Changing directory to ${workDirInput}`)
process.chdir(workDirInput)
@ -37,13 +42,14 @@ async function main(): Promise<void> {
const sha = getCheckRunSha()
// We won't need tracked files if we are not going to create annotations
const annotations = maxAnnotations > 0
const trackedFiles = annotations ? await listFiles() : []
const opts: ParseOptions = {
name,
annotations,
trackedFiles,
workDir
workDir,
annotations
}
const parser = getParser(reporter)
@ -58,6 +64,8 @@ async function main(): Promise<void> {
const result = await parser(files, opts)
const conclusion = result.success ? 'success' : 'failure'
enforceCheckRunLimits(result, maxAnnotations)
core.info(`Creating check run '${name}' with conclusion '${conclusion}'`)
await octokit.checks.create({
head_sha: sha,