mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-15 22:07:09 +01:00
Add option of use-actions-summary
This commit is contained in:
parent
bd77050543
commit
3608ee03fd
17 changed files with 4236 additions and 402 deletions
187
dist/index.js
generated
vendored
187
dist/index.js
generated
vendored
|
|
@ -259,6 +259,7 @@ const github = __importStar(__nccwpck_require__(5438));
|
|||
const fs = __importStar(__nccwpck_require__(7147));
|
||||
const artifact_provider_1 = __nccwpck_require__(7171);
|
||||
const local_file_provider_1 = __nccwpck_require__(9399);
|
||||
const get_annotations_1 = __nccwpck_require__(5867);
|
||||
const get_report_1 = __nccwpck_require__(3737);
|
||||
const dart_json_parser_1 = __nccwpck_require__(4528);
|
||||
const dotnet_trx_parser_1 = __nccwpck_require__(2664);
|
||||
|
|
@ -267,6 +268,7 @@ const jest_junit_parser_1 = __nccwpck_require__(1113);
|
|||
const mocha_json_parser_1 = __nccwpck_require__(6043);
|
||||
const path_utils_1 = __nccwpck_require__(4070);
|
||||
const github_utils_1 = __nccwpck_require__(3522);
|
||||
const markdown_utils_1 = __nccwpck_require__(6482);
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
|
|
@ -294,6 +296,7 @@ class TestReporter {
|
|||
this.failOnError = core.getInput('fail-on-error', { required: true }) === 'true';
|
||||
this.workDirInput = core.getInput('working-directory', { required: false });
|
||||
this.onlySummary = core.getInput('only-summary', { required: false }) === 'true';
|
||||
this.useActionsSummary = core.getInput('use-actions-summary', { required: false }) === 'true';
|
||||
this.badgeTitle = core.getInput('badge-title', { required: false });
|
||||
this.token = core.getInput('token', { required: true });
|
||||
this.context = (0, github_utils_1.getCheckRunContext)();
|
||||
|
|
@ -381,46 +384,43 @@ class TestReporter {
|
|||
const tr = yield parser.parse(file, content);
|
||||
results.push(tr);
|
||||
}
|
||||
// core.info(`Creating check run ${name}`)
|
||||
// const createResp = await this.octokit.checks.create({
|
||||
// head_sha: this.context.sha,
|
||||
// name,
|
||||
// status: 'in_progress',
|
||||
// output: {
|
||||
// title: name,
|
||||
// summary: ''
|
||||
// },
|
||||
// ...github.context.repo
|
||||
// })
|
||||
core.info('Creating report summary');
|
||||
const { listSuites, listTests, onlySummary, badgeTitle } = this;
|
||||
const baseUrl = '';
|
||||
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary, badgeTitle });
|
||||
core.info('Summary content:');
|
||||
core.info(summary);
|
||||
yield fs.promises.writeFile(this.path.replace('*.trx', 'test-summary.md'), summary);
|
||||
core.info('File content:');
|
||||
core.info(fs.readFileSync(this.path.replace('*.trx', 'test-summary.md'), 'utf8'));
|
||||
// core.info('Creating annotations')
|
||||
// const annotations = getAnnotations(results, this.maxAnnotations)
|
||||
// const isFailed = results.some(tr => tr.result === 'failed')
|
||||
// const conclusion = isFailed ? 'failure' : 'success'
|
||||
// const icon = isFailed ? Icon.fail : Icon.success
|
||||
// core.info(`Updating check run conclusion (${conclusion}) and output`)
|
||||
// const resp = await this.octokit.checks.update({
|
||||
// check_run_id: createResp.data.id,
|
||||
// conclusion,
|
||||
// status: 'completed',
|
||||
// output: {
|
||||
// title: `${name} ${icon}`,
|
||||
// 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}`)
|
||||
const { listSuites, listTests, onlySummary, useActionsSummary, badgeTitle } = this;
|
||||
let baseUrl = '';
|
||||
let checkRunId = 0;
|
||||
if (!this.useActionsSummary) {
|
||||
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: {
|
||||
title: name,
|
||||
summary: ''
|
||||
} }, github.context.repo));
|
||||
baseUrl = createResp.data.html_url;
|
||||
checkRunId = createResp.data.id;
|
||||
}
|
||||
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary, useActionsSummary, badgeTitle });
|
||||
if (this.useActionsSummary) {
|
||||
core.info('Summary content:');
|
||||
core.info(summary);
|
||||
yield fs.promises.writeFile(this.path.replace('*.trx', 'test-summary.md'), summary);
|
||||
core.info('File content:');
|
||||
core.info(fs.readFileSync(this.path.replace('*.trx', 'test-summary.md'), 'utf8'));
|
||||
}
|
||||
if (!this.useActionsSummary) {
|
||||
core.info('Creating annotations');
|
||||
const annotations = (0, get_annotations_1.getAnnotations)(results, this.maxAnnotations);
|
||||
const isFailed = results.some(tr => tr.result === 'failed');
|
||||
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: checkRunId, conclusion, status: 'completed', output: {
|
||||
title: `${name} ${icon}`,
|
||||
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}`);
|
||||
}
|
||||
return results;
|
||||
});
|
||||
}
|
||||
|
|
@ -1361,6 +1361,94 @@ class MochaJsonParser {
|
|||
exports.MochaJsonParser = MochaJsonParser;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5867:
|
||||
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getAnnotations = void 0;
|
||||
const markdown_utils_1 = __nccwpck_require__(6482);
|
||||
const parse_utils_1 = __nccwpck_require__(7811);
|
||||
function getAnnotations(results, maxCount) {
|
||||
var _a, _b, _c, _d;
|
||||
if (maxCount === 0) {
|
||||
return [];
|
||||
}
|
||||
// Collect errors from TestRunResults
|
||||
// Merge duplicates if there are more test results files processed
|
||||
const errors = [];
|
||||
const mergeDup = results.length > 1;
|
||||
for (const tr of results) {
|
||||
for (const ts of tr.suites) {
|
||||
for (const tg of ts.groups) {
|
||||
for (const tc of tg.tests) {
|
||||
const err = tc.error;
|
||||
if (err === undefined) {
|
||||
continue;
|
||||
}
|
||||
const path = (_a = err.path) !== null && _a !== void 0 ? _a : tr.path;
|
||||
const line = (_b = err.line) !== null && _b !== void 0 ? _b : 0;
|
||||
if (mergeDup) {
|
||||
const dup = errors.find(e => path === e.path && line === e.line && err.details === e.details);
|
||||
if (dup !== undefined) {
|
||||
dup.testRunPaths.push(tr.path);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
errors.push({
|
||||
testRunPaths: [tr.path],
|
||||
suiteName: ts.name,
|
||||
testName: tg.name ? `${tg.name} ► ${tc.name}` : tc.name,
|
||||
details: err.details,
|
||||
message: (_d = (_c = err.message) !== null && _c !== void 0 ? _c : (0, parse_utils_1.getFirstNonEmptyLine)(err.details)) !== null && _d !== void 0 ? _d : 'Test failed',
|
||||
path,
|
||||
line
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Limit number of created annotations
|
||||
errors.splice(maxCount + 1);
|
||||
const annotations = errors.map(e => {
|
||||
const message = [
|
||||
'Failed test found in:',
|
||||
e.testRunPaths.map(p => ` ${p}`).join('\n'),
|
||||
'Error:',
|
||||
ident((0, markdown_utils_1.fixEol)(e.message), ' ')
|
||||
].join('\n');
|
||||
return enforceCheckRunLimits({
|
||||
path: e.path,
|
||||
start_line: e.line,
|
||||
end_line: e.line,
|
||||
annotation_level: 'failure',
|
||||
title: `${e.suiteName} ► ${e.testName}`,
|
||||
raw_details: (0, markdown_utils_1.fixEol)(e.details),
|
||||
message
|
||||
});
|
||||
});
|
||||
return annotations;
|
||||
}
|
||||
exports.getAnnotations = getAnnotations;
|
||||
function enforceCheckRunLimits(err) {
|
||||
err.title = (0, markdown_utils_1.ellipsis)(err.title || '', 255);
|
||||
err.message = (0, markdown_utils_1.ellipsis)(err.message, 65535);
|
||||
if (err.raw_details) {
|
||||
err.raw_details = (0, markdown_utils_1.ellipsis)(err.raw_details, 65535);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
function ident(text, prefix) {
|
||||
return text
|
||||
.split(/\n/g)
|
||||
.map(line => prefix + line)
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3737:
|
||||
|
|
@ -1399,11 +1487,13 @@ const node_utils_1 = __nccwpck_require__(5824);
|
|||
const parse_utils_1 = __nccwpck_require__(7811);
|
||||
const slugger_1 = __nccwpck_require__(3328);
|
||||
const MAX_REPORT_LENGTH = 65535;
|
||||
const MAX_ACTIONS_SUMMARY_LENGTH = 131072; // 1048576 soon
|
||||
const defaultOptions = {
|
||||
listSuites: 'all',
|
||||
listTests: 'all',
|
||||
baseUrl: '',
|
||||
onlySummary: false,
|
||||
useActionsSummary: true,
|
||||
badgeTitle: 'tests'
|
||||
};
|
||||
function getReport(results, options = defaultOptions) {
|
||||
|
|
@ -1412,7 +1502,7 @@ function getReport(results, options = defaultOptions) {
|
|||
const opts = Object.assign({}, options);
|
||||
let lines = renderReport(results, opts);
|
||||
let report = lines.join('\n');
|
||||
if (getByteLength(report) <= MAX_REPORT_LENGTH) {
|
||||
if (getByteLength(report) <= getMaxReportLength(options)) {
|
||||
return report;
|
||||
}
|
||||
if (opts.listTests === 'all') {
|
||||
|
|
@ -1420,19 +1510,22 @@ function getReport(results, options = defaultOptions) {
|
|||
opts.listTests = 'failed';
|
||||
lines = renderReport(results, opts);
|
||||
report = lines.join('\n');
|
||||
if (getByteLength(report) <= MAX_REPORT_LENGTH) {
|
||||
if (getByteLength(report) <= getMaxReportLength(options)) {
|
||||
return report;
|
||||
}
|
||||
}
|
||||
core.warning(`Test report summary exceeded limit of ${MAX_REPORT_LENGTH} bytes and will be trimmed`);
|
||||
return trimReport(lines);
|
||||
core.warning(`Test report summary exceeded limit of ${getMaxReportLength(options)} bytes and will be trimmed`);
|
||||
return trimReport(lines, options);
|
||||
}
|
||||
exports.getReport = getReport;
|
||||
function trimReport(lines) {
|
||||
function getMaxReportLength(options = defaultOptions) {
|
||||
return options.useActionsSummary ? MAX_ACTIONS_SUMMARY_LENGTH : MAX_REPORT_LENGTH;
|
||||
}
|
||||
function trimReport(lines, options) {
|
||||
const closingBlock = '```';
|
||||
const errorMsg = `**Report exceeded GitHub limit of ${MAX_REPORT_LENGTH} bytes and has been trimmed**`;
|
||||
const errorMsg = `**Report exceeded GitHub limit of ${getMaxReportLength(options)} bytes and has been trimmed**`;
|
||||
const maxErrorMsgLength = closingBlock.length + errorMsg.length + 2;
|
||||
const maxReportLength = MAX_REPORT_LENGTH - maxErrorMsgLength;
|
||||
const maxReportLength = getMaxReportLength(options) - maxErrorMsgLength;
|
||||
let reportLength = 0;
|
||||
let codeBlock = false;
|
||||
let endLineIndex = 0;
|
||||
|
|
@ -1975,7 +2068,7 @@ var Align;
|
|||
Align["None"] = "---";
|
||||
})(Align = exports.Align || (exports.Align = {}));
|
||||
exports.Icon = {
|
||||
skip: ':no_entry_sign:',
|
||||
skip: ':warning:',
|
||||
success: ':white_check_mark:',
|
||||
fail: ':x:'
|
||||
};
|
||||
|
|
|
|||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue