diff --git a/dist/index.js b/dist/index.js index 5e4459a..aac5b52 100644 --- a/dist/index.js +++ b/dist/index.js @@ -284,6 +284,7 @@ function main() { } class TestReporter { constructor() { + this.maxAnnotationsPerBatch = 50; this.artifact = core.getInput('artifact', { required: false }); this.name = core.getInput('name', { required: true }); this.path = core.getInput('path', { required: true }); @@ -298,6 +299,19 @@ class TestReporter { this.showHTMLNotice = core.getInput('show-html-notice', { required: false }) === 'true'; this.token = core.getInput('token', { required: true }); this.context = (0, github_utils_1.getCheckRunContext)(); + this.handleAnnotations = (annotations, requestParams) => __awaiter(this, void 0, void 0, function* () { + const leftAnnotations = [...annotations]; + let response; + do { + const toProcess = leftAnnotations.splice(0, 50); + const status = leftAnnotations.length > 0 ? 'in_progress' : 'completed'; + response = yield this.updateAnnotation(toProcess, Object.assign(Object.assign({}, requestParams), { status })); + } while (leftAnnotations.length > 0); + return response; + }); + this.updateAnnotation = (annotations, requestParams) => __awaiter(this, void 0, void 0, function* () { + return yield this.octokit.rest.checks.update(Object.assign(Object.assign({}, requestParams), { output: Object.assign(Object.assign({}, requestParams.output), { annotations }) })); + }); this.octokit = github.getOctokit(this.token); if (this.listSuites !== 'all' && this.listSuites !== 'failed') { core.setFailed(`Input parameter 'list-suites' has invalid value`); @@ -307,7 +321,7 @@ class TestReporter { core.setFailed(`Input parameter 'list-tests' has invalid value`); return; } - if (isNaN(this.maxAnnotations) || this.maxAnnotations < 0 || this.maxAnnotations > 50) { + if (isNaN(this.maxAnnotations) || this.maxAnnotations > 50) { core.setFailed(`Input parameter 'max-annotations' has invalid value`); return; } @@ -410,7 +424,7 @@ class TestReporter { const conclusion = isFailed ? 'failure' : 'success'; const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success; core.info(`Updating check run conclusion (${conclusion}) and output`); - const resp = yield this.octokit.rest.checks.update(Object.assign({ check_run_id: createResp.data.id, conclusion, status: 'completed', output: { + const resp = yield this.handleAnnotations(annotations, Object.assign({ check_run_id: createResp.data.id, conclusion, status: 'completed', output: { title: `${name} ${icon}`, summary, annotations diff --git a/src/main.ts b/src/main.ts index 403f53e..c6d579b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,13 +1,15 @@ import * as core from '@actions/core' import * as github from '@actions/github' import {GitHub} from '@actions/github/lib/utils' +import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods' import {ArtifactProvider} from './input-providers/artifact-provider' 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 {getAnnotations, Annotation} from './report/get-annotations' +import {UpdateChecksParametersWithOutput} from './report/patch-check' import {getReport} from './report/get-report' import {DartJsonParser} from './parsers/dart-json/dart-json-parser' @@ -31,6 +33,7 @@ async function main(): Promise { } class TestReporter { + readonly maxAnnotationsPerBatch = 50 readonly artifact = core.getInput('artifact', {required: false}) readonly name = core.getInput('name', {required: true}) readonly path = core.getInput('path', {required: true}) @@ -60,7 +63,7 @@ class TestReporter { return } - if (isNaN(this.maxAnnotations) || this.maxAnnotations < 0 || this.maxAnnotations > 50) { + if (isNaN(this.maxAnnotations) || this.maxAnnotations > 50) { core.setFailed(`Input parameter 'max-annotations' has invalid value`) return } @@ -195,7 +198,7 @@ class TestReporter { const icon = isFailed ? Icon.fail : Icon.success core.info(`Updating check run conclusion (${conclusion}) and output`) - const resp = await this.octokit.rest.checks.update({ + const resp = await this.handleAnnotations(annotations, { check_run_id: createResp.data.id, conclusion, status: 'completed', @@ -237,6 +240,29 @@ class TestReporter { throw new Error(`Input variable 'reporter' is set to invalid value '${reporter}'`) } } -} + private handleAnnotations = async ( + annotations: Annotation[], + requestParams: UpdateChecksParametersWithOutput + ): Promise => { + const leftAnnotations = [...annotations] + let response: RestEndpointMethodTypes['checks']['update']['response'] + do { + const toProcess = leftAnnotations.splice(0, 50) + const status = leftAnnotations.length > 0 ? 'in_progress' : 'completed' + response = await this.updateAnnotation(toProcess, {...requestParams, status}) + } while (leftAnnotations.length > 0) + return response + } + + private updateAnnotation = async ( + annotations: Annotation[], + requestParams: UpdateChecksParametersWithOutput + ): Promise => { + return await this.octokit.rest.checks.update({ + ...requestParams, + output: {...requestParams.output, annotations} + }) + } +} main() diff --git a/src/report/get-annotations.ts b/src/report/get-annotations.ts index 1b3e8aa..671e8bd 100644 --- a/src/report/get-annotations.ts +++ b/src/report/get-annotations.ts @@ -2,7 +2,7 @@ import {ellipsis, fixEol} from '../utils/markdown-utils' import {TestRunResult} from '../test-results' import {getFirstNonEmptyLine} from '../utils/parse-utils' -type Annotation = { +export type Annotation = { path: string start_line: number end_line: number diff --git a/src/report/patch-check.ts b/src/report/patch-check.ts new file mode 100644 index 0000000..6e7d37d --- /dev/null +++ b/src/report/patch-check.ts @@ -0,0 +1,6 @@ +import {RestEndpointMethodTypes} from '@octokit/plugin-rest-endpoint-methods' +import {Annotation} from './get-annotations' + +export type UpdateChecksParametersWithOutput = RestEndpointMethodTypes['checks']['update']['parameters'] & { + output: {title: string; summary: string; annotations: Annotation[]} +}