11import * as core from '@actions/core'
2- import { limitPreviousReports , stripAnsi } from '../ctrf'
2+ import { limitPreviousReports , stripAnsi , getEmoji } from '../ctrf'
33import { generateMarkdown } from '../handlebars/core'
44import { Inputs , CtrfReport } from '../types'
55import { readTemplate , reportTypeToInputKey } from '../utils'
66import { BuiltInReports , getBasePath } from '../reports/core'
77import { COMMUNITY_REPORTS_PATH } from '../config'
88import { DEFAULT_REPORT_ORDER } from '../reports/constants'
99import { join } from 'path'
10+ import { isAnyReportEnabled } from '../utils/report-utils'
1011
1112/**
1213 * Generates various views of the CTRF report and adds them to the GitHub Actions summary.
@@ -19,39 +20,30 @@ export function generateViews(inputs: Inputs, report: CtrfReport): void {
1920 core . summary . addHeading ( inputs . title , 2 ) . addEOL ( ) . addEOL ( )
2021 }
2122
22- const isAnyReportEnabled =
23- inputs . summaryReport ||
24- inputs . githubReport ||
25- inputs . failedReport ||
26- inputs . flakyReport ||
27- inputs . flakyRateReport ||
28- inputs . failedFoldedReport ||
29- inputs . failRateReport ||
30- inputs . previousResultsReport ||
31- inputs . aiReport ||
32- inputs . skippedReport ||
33- inputs . testReport ||
34- inputs . testListReport ||
35- inputs . suiteFoldedReport ||
36- inputs . suiteListReport ||
37- inputs . pullRequestReport ||
38- inputs . commitReport ||
39- inputs . customReport ||
40- inputs . communityReport ||
41- inputs . insightsReport ||
42- inputs . slowestReport
43-
44- if ( ! isAnyReportEnabled ) {
23+ if ( ! isAnyReportEnabled ( inputs ) ) {
4524 core . info (
4625 'No specific report selected. Generating default reports: summary, failed, flaky, skipped, and tests.'
4726 )
4827
4928 addViewToSummary ( '### Summary' , BuiltInReports . SummaryTable , report )
50- addViewToSummary ( '### Failed Tests' , BuiltInReports . FailedTable , report )
51- addViewToSummary ( '### Flaky Tests' , BuiltInReports . FlakyTable , report )
52- addViewToSummary ( '### Skipped' , BuiltInReports . SkippedTable , report )
29+ if ( report . results . summary . extra ?. showFailedReports ) {
30+ addViewToSummary ( '### Failed Tests' , BuiltInReports . FailedTable , report )
31+ } else {
32+ core . info ( 'No failed tests to display, skipping failed-report' )
33+ }
34+ if ( report . results . summary . extra ?. showFlakyReports ) {
35+ addViewToSummary ( '### Flaky Tests' , BuiltInReports . FlakyTable , report )
36+ } else {
37+ core . info ( 'No flaky tests to display, skipping flaky-report' )
38+ }
39+ if ( report . results . summary . extra ?. showSkippedReports ) {
40+ addViewToSummary ( '### Skipped' , BuiltInReports . SkippedTable , report )
41+ } else {
42+ core . info ( 'No skipped tests to display, skipping skipped-report' )
43+ }
5344 addViewToSummary ( '### Tests' , BuiltInReports . TestTable , report )
5445
46+ addReportFooters ( report , inputs , false )
5547 addFooter ( )
5648 return
5749 }
@@ -116,16 +108,7 @@ export function generateViews(inputs: Inputs, report: CtrfReport): void {
116108 hasPreviousResultsReports = true
117109 }
118110 }
119-
120- if ( hasPreviousResultsReports && report . results . summary . extra ?. reportsUsed ) {
121- core . summary
122- . addRaw (
123- `<sub><i>Measured over ${ report . results . summary . extra . reportsUsed } runs.</i></sub>`
124- )
125- . addEOL ( )
126- . addEOL ( )
127- }
128-
111+ addReportFooters ( report , inputs , hasPreviousResultsReports )
129112 addFooter ( )
130113}
131114
@@ -138,6 +121,64 @@ function addFooter(): void {
138121 )
139122}
140123
124+ /**
125+ * Adds appropriate footers based on the report's footer display flags
126+ */
127+ function addReportFooters (
128+ report : CtrfReport ,
129+ inputs : Inputs ,
130+ hasPreviousResultsReports : boolean
131+ ) : void {
132+ const extra = report . results . summary . extra
133+ const footerMessages : string [ ] = [ ]
134+
135+ if ( extra ?. includeFailedReportCurrentFooter ) {
136+ footerMessages . push ( `🎉 No failed tests in this run.` )
137+ }
138+ if ( extra ?. includeFailedReportAllFooter ) {
139+ footerMessages . push ( `🎉 No failed tests detected across all runs.` )
140+ }
141+ if ( extra ?. includeFlakyReportCurrentFooter ) {
142+ footerMessages . push ( `${ getEmoji ( 'flaky' ) } No flaky tests in this run.` )
143+ }
144+ if ( extra ?. includeFlakyReportAllFooter ) {
145+ footerMessages . push (
146+ `${ getEmoji ( 'flaky' ) } No flaky tests detected across all runs.`
147+ )
148+ }
149+ if ( extra ?. includeSkippedReportCurrentFooter ) {
150+ footerMessages . push ( `${ getEmoji ( 'skipped' ) } No skipped tests in this run.` )
151+ }
152+
153+ if (
154+ extra ?. includeMeasuredOverFooter &&
155+ extra ?. reportsUsed &&
156+ hasPreviousResultsReports
157+ ) {
158+ footerMessages . push (
159+ `${ getEmoji ( 'duration' ) } Measured over ${ extra . reportsUsed } runs.`
160+ )
161+ }
162+
163+ const hasHiddenReports =
164+ extra ?. includeFailedReportCurrentFooter ||
165+ extra ?. includeFailedReportAllFooter ||
166+ extra ?. includeFlakyReportCurrentFooter ||
167+ extra ?. includeFlakyReportAllFooter ||
168+ extra ?. includeSkippedReportCurrentFooter
169+
170+ if ( hasHiddenReports ) {
171+ footerMessages . push ( `📋 Some reports are hidden` )
172+ }
173+
174+ if ( footerMessages . length > 0 ) {
175+ core . summary
176+ . addRaw ( `<sub><i>${ footerMessages . join ( ' | ' ) } </i></sub>` )
177+ . addEOL ( )
178+ . addEOL ( )
179+ }
180+ }
181+
141182/**
142183 * Generates a specific report based on the report type
143184 *
@@ -172,32 +213,72 @@ function generateReportByType(
172213 addViewToSummary ( '### Insights' , BuiltInReports . InsightsTable , report )
173214 break
174215 case 'failed-report' :
175- core . info ( 'Adding failed tests report to summary' )
176- addViewToSummary ( '### Failed Tests' , BuiltInReports . FailedTable , report )
216+ if ( report . results . summary . extra ?. showFailedReports ) {
217+ core . info ( 'Adding failed tests report to summary' )
218+ addViewToSummary ( '### Failed Tests' , BuiltInReports . FailedTable , report )
219+ } else {
220+ core . info ( 'No failed tests to display, skipping failed-report' )
221+ }
177222 break
178223 case 'fail-rate-report' :
179- core . info ( 'Adding fail rate report to summary' )
180- addViewToSummary ( '### Failed Rate' , BuiltInReports . FailRateTable , report )
224+ if ( report . results . summary . extra ?. showFailedReports ) {
225+ core . info ( 'Adding fail rate report to summary' )
226+ addViewToSummary (
227+ '### Failed Rate' ,
228+ BuiltInReports . FailRateTable ,
229+ report
230+ )
231+ } else {
232+ core . info ( 'No failed tests to display, skipping fail-rate-report' )
233+ }
181234 break
182235 case 'failed-folded-report' :
183- core . info ( 'Adding failed tests folded report to summary' )
184- addViewToSummary ( '### Failed Tests' , BuiltInReports . FailedFolded , report )
236+ if ( report . results . summary . extra ?. showFailedReports ) {
237+ core . info ( 'Adding failed tests folded report to summary' )
238+ addViewToSummary (
239+ '### Failed Tests' ,
240+ BuiltInReports . FailedFolded ,
241+ report
242+ )
243+ } else {
244+ core . info ( 'No failed tests to display, skipping failed-folded-report' )
245+ }
185246 break
186247 case 'flaky-report' :
187- core . info ( 'Adding flaky tests report to summary' )
188- addViewToSummary ( '### Flaky Tests' , BuiltInReports . FlakyTable , report )
248+ if ( report . results . summary . extra ?. showFlakyReports ) {
249+ core . info ( 'Adding flaky tests report to summary' )
250+ addViewToSummary ( '### Flaky Tests' , BuiltInReports . FlakyTable , report )
251+ } else {
252+ core . info ( 'No flaky tests to display, skipping flaky-report' )
253+ }
189254 break
190255 case 'flaky-rate-report' :
191- core . info ( 'Adding flaky rate report to summary' )
192- addViewToSummary ( '### Flaky Rate' , BuiltInReports . FlakyRateTable , report )
256+ if ( report . results . summary . extra ?. showFlakyReports ) {
257+ core . info ( 'Adding flaky rate report to summary' )
258+ addViewToSummary (
259+ '### Flaky Rate' ,
260+ BuiltInReports . FlakyRateTable ,
261+ report
262+ )
263+ } else {
264+ core . info ( 'No flaky tests to display, skipping flaky-rate-report' )
265+ }
193266 break
194267 case 'skipped-report' :
195- core . info ( 'Adding skipped report to summary' )
196- addViewToSummary ( '### Skipped' , BuiltInReports . SkippedTable , report )
268+ if ( report . results . summary . extra ?. showSkippedReports ) {
269+ core . info ( 'Adding skipped report to summary' )
270+ addViewToSummary ( '### Skipped' , BuiltInReports . SkippedTable , report )
271+ } else {
272+ core . info ( 'No skipped tests to display, skipping skipped-report' )
273+ }
197274 break
198275 case 'ai-report' :
199- core . info ( 'Adding AI analysis report to summary' )
200- addViewToSummary ( '### AI Analysis' , BuiltInReports . AiTable , report )
276+ if ( report . results . summary . extra ?. showFailedReports ) {
277+ core . info ( 'Adding AI analysis report to summary' )
278+ addViewToSummary ( '### AI Analysis' , BuiltInReports . AiTable , report )
279+ } else {
280+ core . info ( 'No AI analysis to display, skipping ai-report' )
281+ }
201282 break
202283 case 'pull-request-report' :
203284 core . info ( 'Adding pull request report to summary' )
0 commit comments