Improve logging

This commit is contained in:
Michal Dorner 2021-02-16 22:02:56 +01:00
parent e31d426ac4
commit 09d1ac9fc3
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
3 changed files with 26 additions and 13 deletions

19
dist/index.js generated vendored
View file

@ -281,8 +281,14 @@ class TestReporter {
const results = []; const results = [];
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)) {
const tr = await this.createReport(parser, reportName, files); try {
results.push(...tr); core.startGroup(`Creating test report ${reportName}`);
const tr = await this.createReport(parser, reportName, files);
results.push(...tr);
}
finally {
core.endGroup();
}
} }
const isFailed = results.some(tr => tr.result === 'failed'); const isFailed = results.some(tr => tr.result === 'failed');
const conclusion = isFailed ? 'failure' : 'success'; const conclusion = isFailed ? 'failure' : 'success';
@ -301,12 +307,12 @@ class TestReporter {
} }
async createReport(parser, name, files) { async createReport(parser, name, files) {
if (files.length === 0) { if (files.length === 0) {
core.error(`${name}: No file matches path ${this.path}`); core.warning(`No file matches path ${this.path}`);
return []; return [];
} }
const results = []; const results = [];
for (const { file, content } of files) { for (const { file, content } of files) {
core.info(`Processing test report '${file}'`); core.info(`Processing test results from ${file}`);
const tr = await parser.parse(file, content); const tr = await parser.parse(file, content);
results.push(tr); results.push(tr);
} }
@ -318,8 +324,8 @@ class TestReporter {
const isFailed = results.some(tr => tr.result === 'failed'); const isFailed = results.some(tr => tr.result === 'failed');
const conclusion = isFailed ? 'failure' : 'success'; const conclusion = isFailed ? 'failure' : 'success';
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success; const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
core.info(`Creating check run '${name}' with conclusion '${conclusion}'`); core.info(`Creating check run with conclusion ${conclusion}`);
await this.octokit.checks.create({ const resp = await this.octokit.checks.create({
head_sha: this.context.sha, head_sha: this.context.sha,
name, name,
conclusion, conclusion,
@ -331,6 +337,7 @@ class TestReporter {
}, },
...github.context.repo ...github.context.repo
}); });
core.info(`Check run create response: ${resp.status} - ${resp.url}`);
return results; return results;
} }
getParser(reporter, options) { getParser(reporter, options) {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -96,8 +96,13 @@ class TestReporter {
const results: TestRunResult[] = [] const results: TestRunResult[] = []
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)) {
const tr = await this.createReport(parser, reportName, files) try {
results.push(...tr) core.startGroup(`Creating test report ${reportName}`)
const tr = await this.createReport(parser, reportName, files)
results.push(...tr)
} finally {
core.endGroup()
}
} }
const isFailed = results.some(tr => tr.result === 'failed') const isFailed = results.some(tr => tr.result === 'failed')
@ -120,13 +125,13 @@ class TestReporter {
async createReport(parser: TestParser, name: string, files: FileContent[]): Promise<TestRunResult[]> { async createReport(parser: TestParser, name: string, files: FileContent[]): Promise<TestRunResult[]> {
if (files.length === 0) { if (files.length === 0) {
core.error(`${name}: No file matches path ${this.path}`) core.warning(`No file matches path ${this.path}`)
return [] return []
} }
const results: TestRunResult[] = [] const results: TestRunResult[] = []
for (const {file, content} of files) { for (const {file, content} of files) {
core.info(`Processing test report '${file}'`) core.info(`Processing test results from ${file}`)
const tr = await parser.parse(file, content) const tr = await parser.parse(file, content)
results.push(tr) results.push(tr)
} }
@ -142,8 +147,8 @@ class TestReporter {
const conclusion = isFailed ? 'failure' : 'success' const conclusion = isFailed ? 'failure' : 'success'
const icon = isFailed ? Icon.fail : Icon.success const icon = isFailed ? Icon.fail : Icon.success
core.info(`Creating check run '${name}' with conclusion '${conclusion}'`) core.info(`Creating check run with conclusion ${conclusion}`)
await this.octokit.checks.create({ const resp = await this.octokit.checks.create({
head_sha: this.context.sha, head_sha: this.context.sha,
name, name,
conclusion, conclusion,
@ -155,6 +160,7 @@ class TestReporter {
}, },
...github.context.repo ...github.context.repo
}) })
core.info(`Check run create response: ${resp.status} - ${resp.url}`)
return results return results
} }