mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-17 06:47:09 +01:00
don't fail without write access
This commit is contained in:
parent
26b8b7c891
commit
39a2ecbea2
2 changed files with 120 additions and 111 deletions
103
dist/index.js
generated
vendored
103
dist/index.js
generated
vendored
|
|
@ -283,60 +283,65 @@ class TestReporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
core.info(`Creating check run ${name}`);
|
core.info(`Creating check run ${name}`);
|
||||||
const createResp = yield this.octokit.rest.checks.create(Object.assign({ head_sha: this.context.sha, name, status: 'in_progress', output: {
|
try {
|
||||||
title: name,
|
const createResp = yield this.octokit.rest.checks.create(Object.assign({ head_sha: this.context.sha, name, status: 'in_progress', output: {
|
||||||
summary: ''
|
title: name,
|
||||||
} }, github.context.repo));
|
summary: ''
|
||||||
core.info('Creating report summary');
|
} }, github.context.repo));
|
||||||
const { listSuites, listTests, onlySummary } = this;
|
core.info('Creating report summary');
|
||||||
const baseUrl = createResp.data.html_url || '';
|
const { listSuites, listTests, onlySummary } = this;
|
||||||
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary });
|
const baseUrl = createResp.data.html_url || '';
|
||||||
core.info('Creating annotations');
|
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary });
|
||||||
const annotations = (0, get_annotations_1.getAnnotations)(results, this.maxAnnotations);
|
core.info('Creating annotations');
|
||||||
const isFailed = results.some(tr => tr.result === 'failed');
|
const annotations = (0, get_annotations_1.getAnnotations)(results, this.maxAnnotations);
|
||||||
const conclusion = isFailed ? 'failure' : 'success';
|
const isFailed = results.some(tr => tr.result === 'failed');
|
||||||
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
|
const conclusion = isFailed ? 'failure' : 'success';
|
||||||
core.info(`Updating check run conclusion (${conclusion}) and output`);
|
const icon = isFailed ? markdown_utils_1.Icon.fail : markdown_utils_1.Icon.success;
|
||||||
const resp = yield this.octokit.rest.checks.update(Object.assign({ check_run_id: createResp.data.id, conclusion, status: 'completed', output: {
|
core.info(`Updating check run conclusion (${conclusion}) and output`);
|
||||||
title: `${name} ${icon}`,
|
const resp = yield this.octokit.rest.checks.update(Object.assign({ check_run_id: createResp.data.id, conclusion, status: 'completed', output: {
|
||||||
summary,
|
title: `${name} ${icon}`,
|
||||||
annotations
|
summary,
|
||||||
} }, github.context.repo));
|
annotations
|
||||||
core.info(`Check run create response: ${resp.status}`);
|
} }, github.context.repo));
|
||||||
core.info(`Check run URL: ${resp.data.url}`);
|
core.info(`Check run create response: ${resp.status}`);
|
||||||
core.info(`Check run HTML: ${resp.data.html_url}`);
|
core.info(`Check run URL: ${resp.data.url}`);
|
||||||
core.setOutput('url', resp.data.url);
|
core.info(`Check run HTML: ${resp.data.html_url}`);
|
||||||
core.setOutput('url_html', resp.data.html_url);
|
core.setOutput('url', resp.data.url);
|
||||||
core.info(`Check run details: ${resp.data.details_url}`);
|
core.setOutput('url_html', resp.data.html_url);
|
||||||
if (this.slackWebhook && this.context.branch === 'master') {
|
core.info(`Check run details: ${resp.data.details_url}`);
|
||||||
const webhook = new webhook_1.IncomingWebhook(this.slackWebhook);
|
if (this.slackWebhook && this.context.branch === 'master') {
|
||||||
const passed = results.reduce((sum, tr) => sum + tr.passed, 0);
|
const webhook = new webhook_1.IncomingWebhook(this.slackWebhook);
|
||||||
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
|
const passed = results.reduce((sum, tr) => sum + tr.passed, 0);
|
||||||
const failed = results.reduce((sum, tr) => sum + tr.failed, 0);
|
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0);
|
||||||
const req = {
|
const failed = results.reduce((sum, tr) => sum + tr.failed, 0);
|
||||||
blocks: [
|
const req = {
|
||||||
{
|
blocks: [
|
||||||
|
{
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: `:large_green_circle: ${passed} :large_orange_circle: ${skipped} :red_circle: ${failed} <${resp.data.html_url}|(view)>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
results.map((tr, runIndex) => {
|
||||||
|
if (tr.failed === 0)
|
||||||
|
return;
|
||||||
|
const runName = tr.path.slice(0, tr.path.indexOf('/TestResults/'));
|
||||||
|
req.blocks.push({
|
||||||
type: 'section',
|
type: 'section',
|
||||||
text: {
|
text: {
|
||||||
type: 'mrkdwn',
|
type: 'mrkdwn',
|
||||||
text: `:large_green_circle: ${passed} :large_orange_circle: ${skipped} :red_circle: ${failed} <${resp.data.html_url}|(view)>`
|
text: `:red_circle: ${tr.failed} in <${resp.data.html_url}#r${runIndex}|${runName}>`
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
]
|
|
||||||
};
|
|
||||||
results.map((tr, runIndex) => {
|
|
||||||
if (tr.failed === 0)
|
|
||||||
return;
|
|
||||||
const runName = tr.path.slice(0, tr.path.indexOf('/TestResults/'));
|
|
||||||
req.blocks.push({
|
|
||||||
type: 'section',
|
|
||||||
text: {
|
|
||||||
type: 'mrkdwn',
|
|
||||||
text: `:red_circle: ${tr.failed} in <${resp.data.html_url}#r${runIndex}|${runName}>`
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
yield webhook.send(req);
|
||||||
yield webhook.send(req);
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Could not create check to store the results`);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
128
src/main.ts
128
src/main.ts
|
|
@ -184,80 +184,84 @@ class TestReporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Creating check run ${name}`)
|
core.info(`Creating check run ${name}`)
|
||||||
const createResp = await this.octokit.rest.checks.create({
|
try {
|
||||||
head_sha: this.context.sha,
|
const createResp = await this.octokit.rest.checks.create({
|
||||||
name,
|
head_sha: this.context.sha,
|
||||||
status: 'in_progress',
|
name,
|
||||||
output: {
|
status: 'in_progress',
|
||||||
title: name,
|
output: {
|
||||||
summary: ''
|
title: name,
|
||||||
},
|
summary: ''
|
||||||
...github.context.repo
|
},
|
||||||
})
|
...github.context.repo
|
||||||
|
})
|
||||||
|
|
||||||
core.info('Creating report summary')
|
core.info('Creating report summary')
|
||||||
const {listSuites, listTests, onlySummary} = this
|
const {listSuites, listTests, onlySummary} = this
|
||||||
const baseUrl = createResp.data.html_url || ''
|
const baseUrl = createResp.data.html_url || ''
|
||||||
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary})
|
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary})
|
||||||
|
|
||||||
core.info('Creating annotations')
|
core.info('Creating annotations')
|
||||||
const annotations = getAnnotations(results, this.maxAnnotations)
|
const annotations = getAnnotations(results, this.maxAnnotations)
|
||||||
|
|
||||||
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 ? Icon.fail : Icon.success
|
const icon = isFailed ? Icon.fail : Icon.success
|
||||||
|
|
||||||
core.info(`Updating check run conclusion (${conclusion}) and output`)
|
core.info(`Updating check run conclusion (${conclusion}) and output`)
|
||||||
const resp = await this.octokit.rest.checks.update({
|
const resp = await this.octokit.rest.checks.update({
|
||||||
check_run_id: createResp.data.id,
|
check_run_id: createResp.data.id,
|
||||||
conclusion,
|
conclusion,
|
||||||
status: 'completed',
|
status: 'completed',
|
||||||
output: {
|
output: {
|
||||||
title: `${name} ${icon}`,
|
title: `${name} ${icon}`,
|
||||||
summary,
|
summary,
|
||||||
annotations
|
annotations
|
||||||
},
|
},
|
||||||
...github.context.repo
|
...github.context.repo
|
||||||
})
|
})
|
||||||
core.info(`Check run create response: ${resp.status}`)
|
core.info(`Check run create response: ${resp.status}`)
|
||||||
core.info(`Check run URL: ${resp.data.url}`)
|
core.info(`Check run URL: ${resp.data.url}`)
|
||||||
core.info(`Check run HTML: ${resp.data.html_url}`)
|
core.info(`Check run HTML: ${resp.data.html_url}`)
|
||||||
core.setOutput('url', resp.data.url)
|
core.setOutput('url', resp.data.url)
|
||||||
core.setOutput('url_html', resp.data.html_url)
|
core.setOutput('url_html', resp.data.html_url)
|
||||||
core.info(`Check run details: ${resp.data.details_url}`)
|
core.info(`Check run details: ${resp.data.details_url}`)
|
||||||
|
|
||||||
if (this.slackWebhook && this.context.branch === 'master') {
|
if (this.slackWebhook && this.context.branch === 'master') {
|
||||||
const webhook = new IncomingWebhook(this.slackWebhook)
|
const webhook = new IncomingWebhook(this.slackWebhook)
|
||||||
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
|
const passed = results.reduce((sum, tr) => sum + tr.passed, 0)
|
||||||
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
|
const skipped = results.reduce((sum, tr) => sum + tr.skipped, 0)
|
||||||
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
|
const failed = results.reduce((sum, tr) => sum + tr.failed, 0)
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
blocks: [
|
blocks: [
|
||||||
{
|
{
|
||||||
|
type: 'section',
|
||||||
|
text: {
|
||||||
|
type: 'mrkdwn',
|
||||||
|
text: `:large_green_circle: ${passed} :large_orange_circle: ${skipped} :red_circle: ${failed} <${resp.data.html_url}|(view)>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
results.map((tr, runIndex) => {
|
||||||
|
if (tr.failed === 0) return
|
||||||
|
const runName = tr.path.slice(0, tr.path.indexOf('/TestResults/'))
|
||||||
|
|
||||||
|
req.blocks.push({
|
||||||
type: 'section',
|
type: 'section',
|
||||||
text: {
|
text: {
|
||||||
type: 'mrkdwn',
|
type: 'mrkdwn',
|
||||||
text: `:large_green_circle: ${passed} :large_orange_circle: ${skipped} :red_circle: ${failed} <${resp.data.html_url}|(view)>`
|
text: `:red_circle: ${tr.failed} in <${resp.data.html_url}#r${runIndex}|${runName}>`
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
results.map((tr, runIndex) => {
|
|
||||||
if (tr.failed === 0) return
|
|
||||||
const runName = tr.path.slice(0, tr.path.indexOf('/TestResults/'))
|
|
||||||
|
|
||||||
req.blocks.push({
|
|
||||||
type: 'section',
|
|
||||||
text: {
|
|
||||||
type: 'mrkdwn',
|
|
||||||
text: `:red_circle: ${tr.failed} in <${resp.data.html_url}#r${runIndex}|${runName}>`
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
await webhook.send(req)
|
await webhook.send(req)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Could not create check to store the results`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue