remove output-to parameter

This commit is contained in:
Patrik Husfloen 2024-03-01 14:12:45 +01:00
parent bd65e34c96
commit 4a79aca441
3 changed files with 58 additions and 158 deletions

View file

@ -70,13 +70,6 @@ inputs:
Detailed listing of test suites and test cases will be skipped. Detailed listing of test suites and test cases will be skipped.
default: 'false' default: 'false'
required: false required: false
output-to:
description: |
The location to write the report to. Supported options:
- checks
- step-summary
default: 'step-summary'
required: false
token: token:
description: GitHub Access Token description: GitHub Access Token
required: false required: false

99
dist/index.js generated vendored
View file

@ -302,7 +302,6 @@ class TestReporter {
this.workDirInput = core.getInput('working-directory', { required: false }); this.workDirInput = core.getInput('working-directory', { required: false });
this.buildDirInput = core.getInput('build-directory', { required: false }); this.buildDirInput = core.getInput('build-directory', { required: false });
this.onlySummary = core.getInput('only-summary', { required: false }) === 'true'; this.onlySummary = core.getInput('only-summary', { required: false }) === 'true';
this.outputTo = core.getInput('output-to', { required: false });
this.token = core.getInput('token', { required: true }); this.token = core.getInput('token', { required: true });
this.slugPrefix = ''; this.slugPrefix = '';
this.context = (0, github_utils_1.getCheckRunContext)(); this.context = (0, github_utils_1.getCheckRunContext)();
@ -319,13 +318,7 @@ class TestReporter {
core.setFailed(`Input parameter 'max-annotations' has invalid value`); core.setFailed(`Input parameter 'max-annotations' has invalid value`);
return; return;
} }
if (this.outputTo !== 'checks' && this.outputTo !== 'step-summary') { this.slugPrefix = createSlugPrefix();
core.setFailed(`Input parameter 'output-to' has invalid value`);
return;
}
if (this.outputTo === 'step-summary') {
this.slugPrefix = createSlugPrefix();
}
} }
run() { run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -391,7 +384,7 @@ class TestReporter {
}); });
} }
createReport(parser, name, files) { createReport(parser, name, files) {
var _a, _b; var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (files.length === 0) { if (files.length === 0) {
core.warning(`No file matches path ${this.path}`); core.warning(`No file matches path ${this.path}`);
@ -409,26 +402,9 @@ class TestReporter {
throw error; throw error;
} }
} }
let createResp = null;
let baseUrl = ''; let baseUrl = '';
let check_run_id = 0; const run_attempt = (_a = process.env['GITHUB_RUN_ATTEMPT']) !== null && _a !== void 0 ? _a : 1;
switch (this.outputTo) { baseUrl = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}/attempts/${run_attempt}`;
case 'checks': {
core.info(`Creating check run ${name}`);
createResp = yield this.octokit.rest.checks.create(Object.assign({ head_sha: this.context.sha, name, status: 'in_progress', output: {
title: name,
summary: ''
} }, github.context.repo));
baseUrl = (_a = createResp.data.html_url) !== null && _a !== void 0 ? _a : '';
check_run_id = createResp.data.id;
break;
}
case 'step-summary': {
const run_attempt = (_b = process.env['GITHUB_RUN_ATTEMPT']) !== null && _b !== void 0 ? _b : 1;
baseUrl = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}/attempts/${run_attempt}`;
break;
}
}
core.info('Creating report summary'); core.info('Creating report summary');
const { listSuites, listTests, onlySummary, slugPrefix } = this; const { listSuites, listTests, onlySummary, slugPrefix } = this;
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, slugPrefix, onlySummary }); const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, slugPrefix, onlySummary });
@ -441,49 +417,32 @@ class TestReporter {
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0); const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
const shortSummary = `${passed} passed, ${failed} failed and ${skipped} skipped `; const shortSummary = `${passed} passed, ${failed} failed and ${skipped} skipped `;
core.info(`Updating check run conclusion (${conclusion}) and output`); core.info(`Updating check run conclusion (${conclusion}) and output`);
switch (this.outputTo) { core.summary.addRaw(`# ${shortSummary}`);
case 'checks': { core.summary.addRaw(summary);
const resp = yield this.octokit.rest.checks.update(Object.assign({ check_run_id, yield core.summary.write();
conclusion, status: 'completed', output: { for (const annotation of annotations) {
title: shortSummary, let fn;
summary, switch (annotation.annotation_level) {
annotations case 'failure':
} }, github.context.repo)); fn = core.error;
core.info(`Check run create response: ${resp.status}`); break;
core.info(`Check run URL: ${resp.data.url}`); case 'warning':
core.info(`Check run HTML: ${resp.data.html_url}`); fn = core.warning;
break; break;
} case 'notice':
case 'step-summary': { fn = core.notice;
core.summary.addRaw(`# ${shortSummary}`); break;
core.summary.addRaw(summary); default:
yield core.summary.write(); continue;
for (const annotation of annotations) {
let fn;
switch (annotation.annotation_level) {
case 'failure':
fn = core.error;
break;
case 'warning':
fn = core.warning;
break;
case 'notice':
fn = core.notice;
break;
default:
continue;
}
fn(annotation.message, {
title: annotation.title,
file: annotation.path,
startLine: annotation.start_line,
endLine: annotation.end_line,
startColumn: annotation.start_column,
endColumn: annotation.end_column
});
}
break;
} }
fn(annotation.message, {
title: annotation.title,
file: annotation.path,
startLine: annotation.start_line,
endLine: annotation.end_line,
startColumn: annotation.start_column,
endColumn: annotation.end_column
});
} }
return results; return results;
}); });

View file

@ -53,7 +53,6 @@ class TestReporter {
readonly workDirInput = core.getInput('working-directory', {required: false}) readonly workDirInput = core.getInput('working-directory', {required: false})
readonly buildDirInput = core.getInput('build-directory', {required: false}) readonly buildDirInput = core.getInput('build-directory', {required: false})
readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true' readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true'
readonly outputTo = core.getInput('output-to', {required: false})
readonly token = core.getInput('token', {required: true}) readonly token = core.getInput('token', {required: true})
readonly slugPrefix: string = '' readonly slugPrefix: string = ''
readonly octokit: InstanceType<typeof GitHub> readonly octokit: InstanceType<typeof GitHub>
@ -77,14 +76,7 @@ class TestReporter {
return return
} }
if (this.outputTo !== 'checks' && this.outputTo !== 'step-summary') { this.slugPrefix = createSlugPrefix()
core.setFailed(`Input parameter 'output-to' has invalid value`)
return
}
if (this.outputTo === 'step-summary') {
this.slugPrefix = createSlugPrefix()
}
} }
async run(): Promise<void> { async run(): Promise<void> {
@ -185,33 +177,10 @@ class TestReporter {
} }
} }
let createResp = null
let baseUrl = '' let baseUrl = ''
let check_run_id = 0
switch (this.outputTo) { const run_attempt = process.env['GITHUB_RUN_ATTEMPT'] ?? 1
case 'checks': { baseUrl = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}/attempts/${run_attempt}`
core.info(`Creating check run ${name}`)
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 ?? ''
check_run_id = createResp.data.id
break
}
case 'step-summary': {
const run_attempt = process.env['GITHUB_RUN_ATTEMPT'] ?? 1
baseUrl = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}/attempts/${run_attempt}`
break
}
}
core.info('Creating report summary') core.info('Creating report summary')
const {listSuites, listTests, onlySummary, slugPrefix} = this const {listSuites, listTests, onlySummary, slugPrefix} = this
@ -229,55 +198,34 @@ class TestReporter {
const shortSummary = `${passed} passed, ${failed} failed and ${skipped} skipped ` const shortSummary = `${passed} passed, ${failed} failed and ${skipped} skipped `
core.info(`Updating check run conclusion (${conclusion}) and output`) core.info(`Updating check run conclusion (${conclusion}) and output`)
switch (this.outputTo) { core.summary.addRaw(`# ${shortSummary}`)
case 'checks': { core.summary.addRaw(summary)
const resp = await this.octokit.rest.checks.update({ await core.summary.write()
check_run_id,
conclusion,
status: 'completed',
output: {
title: shortSummary,
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}`)
break
}
case 'step-summary': {
core.summary.addRaw(`# ${shortSummary}`)
core.summary.addRaw(summary)
await core.summary.write()
for (const annotation of annotations) {
let fn
switch (annotation.annotation_level) {
case 'failure':
fn = core.error
break
case 'warning':
fn = core.warning
break
case 'notice':
fn = core.notice
break
default:
continue
}
fn(annotation.message, { for (const annotation of annotations) {
title: annotation.title, let fn
file: annotation.path, switch (annotation.annotation_level) {
startLine: annotation.start_line, case 'failure':
endLine: annotation.end_line, fn = core.error
startColumn: annotation.start_column, break
endColumn: annotation.end_column case 'warning':
}) fn = core.warning
} break
break case 'notice':
fn = core.notice
break
default:
continue
} }
fn(annotation.message, {
title: annotation.title,
file: annotation.path,
startLine: annotation.start_line,
endLine: annotation.end_line,
startColumn: annotation.start_column,
endColumn: annotation.end_column
})
} }
return results return results