trying to add link as output

This commit is contained in:
nicolo.castro 2023-04-27 14:08:35 +02:00
parent 0a5dc1ab75
commit c82c974817
No known key found for this signature in database
GPG key ID: CD97C9B5EF7D74A8
3 changed files with 25 additions and 7 deletions

View file

@ -89,6 +89,8 @@ outputs:
description: Count of skipped tests description: Count of skipped tests
time: time:
description: Test execution time [ms] description: Test execution time [ms]
runHtmlUrl:
description: comma separated list of html links to test results
runs: runs:
using: 'node16' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'

12
dist/index.js generated vendored
View file

@ -339,12 +339,16 @@ class TestReporter {
core.info(`Using test report parser '${this.reporter}'`); core.info(`Using test report parser '${this.reporter}'`);
const parser = this.getParser(this.reporter, options); const parser = this.getParser(this.reporter, options);
const results = []; const results = [];
const outputHtml = [];
const input = yield inputProvider.load(); const input = yield inputProvider.load();
for (const [reportName, files] of Object.entries(input)) { for (const [reportName, files] of Object.entries(input)) {
try { try {
core.startGroup(`Creating test report ${reportName}`); core.startGroup(`Creating test report ${reportName}`);
const tr = yield this.createReport(parser, reportName, files); const [tr, html] = yield this.createReport(parser, reportName, files);
results.push(...tr); results.push(...tr);
if (html != null) {
outputHtml.push(html);
}
} }
finally { finally {
core.endGroup(); core.endGroup();
@ -356,11 +360,13 @@ class TestReporter {
const failed = results.reduce((sum, tr) => sum + tr.failed, 0); const failed = results.reduce((sum, tr) => sum + tr.failed, 0);
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0); const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
const time = results.reduce((sum, tr) => sum + tr.time, 0); const time = results.reduce((sum, tr) => sum + tr.time, 0);
const html = [...new Set(outputHtml)].join(',');
core.setOutput('conclusion', conclusion); core.setOutput('conclusion', conclusion);
core.setOutput('passed', passed); core.setOutput('passed', passed);
core.setOutput('failed', failed); core.setOutput('failed', failed);
core.setOutput('skipped', skipped); core.setOutput('skipped', skipped);
core.setOutput('time', time); core.setOutput('time', time);
core.setOutput('runHtmlUrl', html);
if (this.failOnError && isFailed) { if (this.failOnError && isFailed) {
core.setFailed(`Failed test were found and 'fail-on-error' option is set to ${this.failOnError}`); core.setFailed(`Failed test were found and 'fail-on-error' option is set to ${this.failOnError}`);
return; return;
@ -375,7 +381,7 @@ class TestReporter {
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}`);
return []; return [[], ''];
} }
core.info(`Processing test results for check run ${name}`); core.info(`Processing test results for check run ${name}`);
const results = []; const results = [];
@ -416,7 +422,7 @@ class TestReporter {
core.info('*** showhtmlnotice set to true'); core.info('*** showhtmlnotice set to true');
console.log(`::notice title=Test Results::${resp.data.html_url}`); console.log(`::notice title=Test Results::${resp.data.html_url}`);
} }
return results; return [results, resp.data.html_url];
}); });
} }
getParser(reporter, options) { getParser(reporter, options) {

View file

@ -107,12 +107,16 @@ class TestReporter {
const parser = this.getParser(this.reporter, options) const parser = this.getParser(this.reporter, options)
const results: TestRunResult[] = [] const results: TestRunResult[] = []
const outputHtml: string[] = []
const input = await inputProvider.load() const input = await inputProvider.load()
for (const [reportName, files] of Object.entries(input)) { for (const [reportName, files] of Object.entries(input)) {
try { try {
core.startGroup(`Creating test report ${reportName}`) core.startGroup(`Creating test report ${reportName}`)
const tr = await this.createReport(parser, reportName, files) const [tr, html] = await this.createReport(parser, reportName, files)
results.push(...tr) results.push(...tr)
if (html != null) {
outputHtml.push(html)
}
} finally { } finally {
core.endGroup() core.endGroup()
} }
@ -124,12 +128,14 @@ class TestReporter {
const failed = results.reduce((sum, tr) => sum + tr.failed, 0) const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0) const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
const time = results.reduce((sum, tr) => sum + tr.time, 0) const time = results.reduce((sum, tr) => sum + tr.time, 0)
const html = [...new Set(outputHtml)].join(',')
core.setOutput('conclusion', conclusion) core.setOutput('conclusion', conclusion)
core.setOutput('passed', passed) core.setOutput('passed', passed)
core.setOutput('failed', failed) core.setOutput('failed', failed)
core.setOutput('skipped', skipped) core.setOutput('skipped', skipped)
core.setOutput('time', time) core.setOutput('time', time)
core.setOutput('runHtmlUrl', html)
if (this.failOnError && isFailed) { if (this.failOnError && isFailed) {
core.setFailed(`Failed test were found and 'fail-on-error' option is set to ${this.failOnError}`) core.setFailed(`Failed test were found and 'fail-on-error' option is set to ${this.failOnError}`)
@ -142,10 +148,14 @@ class TestReporter {
} }
} }
async createReport(parser: TestParser, name: string, files: FileContent[]): Promise<TestRunResult[]> { async createReport(
parser: TestParser,
name: string,
files: FileContent[]
): Promise<[TestRunResult[], string | null]> {
if (files.length === 0) { if (files.length === 0) {
core.warning(`No file matches path ${this.path}`) core.warning(`No file matches path ${this.path}`)
return [] return [[], '']
} }
core.info(`Processing test results for check run ${name}`) core.info(`Processing test results for check run ${name}`)
@ -204,7 +214,7 @@ class TestReporter {
console.log(`::notice title=Test Results::${resp.data.html_url}`) console.log(`::notice title=Test Results::${resp.data.html_url}`)
} }
return results return [results, resp.data.html_url]
} }
getParser(reporter: string, options: ParseOptions): TestParser { getParser(reporter: string, options: ParseOptions): TestParser {