Feature: Add summary title

Add new option `report-title` to add H1 title to the Markdown report

Resolves #540
This commit is contained in:
Michael Marcus 2025-03-27 12:33:59 -04:00 committed by Jozef Izso
parent d1bf678c89
commit 0841c8130e
20 changed files with 65 additions and 8 deletions

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%205%20failed%2C%201%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-3%20passed%2C%205%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%205%20failed%2C%201%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-5%20passed%2C%205%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-803%20passed%2C%201%20skipped-success) ![Tests passed successfully](https://img.shields.io/badge/tests-803%20passed%2C%201%20skipped-success)
<details><summary>Expand for details</summary> <details><summary>Expand for details</summary>

View file

@ -1,3 +1,4 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success) ![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
<details><summary>Expand for details</summary> <details><summary>Expand for details</summary>

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success) ![Tests passed successfully](https://img.shields.io/badge/tests-1%20passed-success)
<details><summary>Expand for details</summary> <details><summary>Expand for details</summary>

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-4207%20passed%2C%202%20failed%2C%2030%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-4207%20passed%2C%202%20failed%2C%2030%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20failed-critical) ![Tests failed](https://img.shields.io/badge/tests-1%20failed-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%204%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-833%20passed%2C%206%20skipped-success) ![Tests passed successfully](https://img.shields.io/badge/tests-833%20passed%2C%206%20skipped-success)
<details><summary>Expand for details</summary> <details><summary>Expand for details</summary>

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-268%20passed%2C%201%20failed-critical) ![Tests failed](https://img.shields.io/badge/tests-268%20passed%2C%201%20failed-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20failed%2C%201%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-1%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-793%20passed%2C%201%20failed%2C%2014%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-793%20passed%2C%201%20failed%2C%2014%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20failed%2C%201%20skipped-critical) ![Tests failed](https://img.shields.io/badge/tests-1%20passed%2C%201%20failed%2C%201%20skipped-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

View file

@ -1,3 +1,4 @@
# Test Results
![Tests passed successfully](https://img.shields.io/badge/tests-67%20passed%2C%2012%20skipped-success) ![Tests passed successfully](https://img.shields.io/badge/tests-67%20passed%2C%2012%20skipped-success)
<details><summary>Expand for details</summary> <details><summary>Expand for details</summary>

View file

@ -1,3 +1,4 @@
# Test Results
![Tests failed](https://img.shields.io/badge/tests-2%20passed%2C%201%20failed-critical) ![Tests failed](https://img.shields.io/badge/tests-2%20passed%2C%201%20failed-critical)
|Report|Passed|Failed|Skipped|Time| |Report|Passed|Failed|Skipped|Time|
|:---|---:|---:|---:|---:| |:---|---:|---:|---:|---:|

27
dist/index.js generated vendored
View file

@ -307,6 +307,7 @@ class TestReporter {
onlySummary = core.getInput('only-summary', { required: false }) === 'true'; onlySummary = core.getInput('only-summary', { required: false }) === 'true';
useActionsSummary = core.getInput('use-actions-summary', { required: false }) === 'true'; useActionsSummary = core.getInput('use-actions-summary', { required: false }) === 'true';
badgeTitle = core.getInput('badge-title', { required: false }); badgeTitle = core.getInput('badge-title', { required: false });
reportTitle = core.getInput('report-title', { required: false });
token = core.getInput('token', { required: true }); token = core.getInput('token', { required: true });
octokit; octokit;
context = (0, github_utils_1.getCheckRunContext)(); context = (0, github_utils_1.getCheckRunContext)();
@ -399,10 +400,18 @@ class TestReporter {
throw error; throw error;
} }
} }
const { listSuites, listTests, onlySummary, useActionsSummary, badgeTitle } = this; const { listSuites, listTests, onlySummary, useActionsSummary, badgeTitle, reportTitle } = this;
let baseUrl = ''; let baseUrl = '';
if (this.useActionsSummary) { if (this.useActionsSummary) {
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary, useActionsSummary, badgeTitle }); const summary = (0, get_report_1.getReport)(results, {
listSuites,
listTests,
baseUrl,
onlySummary,
useActionsSummary,
badgeTitle,
reportTitle
});
core.info('Summary content:'); core.info('Summary content:');
core.info(summary); core.info(summary);
await core.summary.addRaw(summary).write(); await core.summary.addRaw(summary).write();
@ -421,7 +430,15 @@ class TestReporter {
}); });
core.info('Creating report summary'); core.info('Creating report summary');
baseUrl = createResp.data.html_url; baseUrl = createResp.data.html_url;
const summary = (0, get_report_1.getReport)(results, { listSuites, listTests, baseUrl, onlySummary, useActionsSummary, badgeTitle }); const summary = (0, get_report_1.getReport)(results, {
listSuites,
listTests,
baseUrl,
onlySummary,
useActionsSummary,
badgeTitle,
reportTitle
});
core.info('Creating annotations'); core.info('Creating annotations');
const annotations = (0, get_annotations_1.getAnnotations)(results, this.maxAnnotations); const annotations = (0, get_annotations_1.getAnnotations)(results, this.maxAnnotations);
const isFailed = this.failOnError && results.some(tr => tr.result === 'failed'); const isFailed = this.failOnError && results.some(tr => tr.result === 'failed');
@ -1800,7 +1817,8 @@ const defaultOptions = {
baseUrl: '', baseUrl: '',
onlySummary: false, onlySummary: false,
useActionsSummary: true, useActionsSummary: true,
badgeTitle: 'tests' badgeTitle: 'tests',
reportTitle: 'Test Results'
}; };
function getReport(results, options = defaultOptions) { function getReport(results, options = defaultOptions) {
core.info('Generating check run summary'); core.info('Generating check run summary');
@ -1863,6 +1881,7 @@ function getByteLength(text) {
} }
function renderReport(results, options) { function renderReport(results, options) {
const sections = []; const sections = [];
sections.push(`# ${options.reportTitle}`);
const badge = getReportBadge(results, options); const badge = getReportBadge(results, options);
sections.push(badge); sections.push(badge);
const runs = getTestRunsReport(results, options); const runs = getTestRunsReport(results, options);

View file

@ -47,6 +47,7 @@ class TestReporter {
readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true' readonly onlySummary = core.getInput('only-summary', {required: false}) === 'true'
readonly useActionsSummary = core.getInput('use-actions-summary', {required: false}) === 'true' readonly useActionsSummary = core.getInput('use-actions-summary', {required: false}) === 'true'
readonly badgeTitle = core.getInput('badge-title', {required: false}) readonly badgeTitle = core.getInput('badge-title', {required: false})
readonly reportTitle = core.getInput('report-title', {required: false})
readonly token = core.getInput('token', {required: true}) readonly token = core.getInput('token', {required: true})
readonly octokit: InstanceType<typeof GitHub> readonly octokit: InstanceType<typeof GitHub>
readonly context = getCheckRunContext() readonly context = getCheckRunContext()
@ -164,11 +165,19 @@ class TestReporter {
} }
} }
const {listSuites, listTests, onlySummary, useActionsSummary, badgeTitle} = this const {listSuites, listTests, onlySummary, useActionsSummary, badgeTitle, reportTitle} = this
let baseUrl = '' let baseUrl = ''
if (this.useActionsSummary) { if (this.useActionsSummary) {
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary, useActionsSummary, badgeTitle}) const summary = getReport(results, {
listSuites,
listTests,
baseUrl,
onlySummary,
useActionsSummary,
badgeTitle,
reportTitle
})
core.info('Summary content:') core.info('Summary content:')
core.info(summary) core.info(summary)
@ -188,7 +197,15 @@ class TestReporter {
core.info('Creating report summary') core.info('Creating report summary')
baseUrl = createResp.data.html_url as string baseUrl = createResp.data.html_url as string
const summary = getReport(results, {listSuites, listTests, baseUrl, onlySummary, useActionsSummary, badgeTitle}) const summary = getReport(results, {
listSuites,
listTests,
baseUrl,
onlySummary,
useActionsSummary,
badgeTitle,
reportTitle
})
core.info('Creating annotations') core.info('Creating annotations')
const annotations = getAnnotations(results, this.maxAnnotations) const annotations = getAnnotations(results, this.maxAnnotations)

View file

@ -15,6 +15,7 @@ export interface ReportOptions {
onlySummary: boolean onlySummary: boolean
useActionsSummary: boolean useActionsSummary: boolean
badgeTitle: string badgeTitle: string
reportTitle: string
} }
const defaultOptions: ReportOptions = { const defaultOptions: ReportOptions = {
@ -23,7 +24,8 @@ const defaultOptions: ReportOptions = {
baseUrl: '', baseUrl: '',
onlySummary: false, onlySummary: false,
useActionsSummary: true, useActionsSummary: true,
badgeTitle: 'tests' badgeTitle: 'tests',
reportTitle: 'Test Results'
} }
export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string { export function getReport(results: TestRunResult[], options: ReportOptions = defaultOptions): string {
@ -101,6 +103,8 @@ function getByteLength(text: string): number {
function renderReport(results: TestRunResult[], options: ReportOptions): string[] { function renderReport(results: TestRunResult[], options: ReportOptions): string[] {
const sections: string[] = [] const sections: string[] = []
sections.push(`# ${options.reportTitle}`)
const badge = getReportBadge(results, options) const badge = getReportBadge(results, options)
sections.push(badge) sections.push(badge)