11import * as core from '@actions/core'
22import { limitPreviousReports , stripAnsi , getEmoji } from '../ctrf'
33import { generateMarkdown } from '../handlebars/core'
4- import { Inputs , ReportConditionals } from '../types'
4+ import { Inputs , PreviousResult , ReportConditionals } from '../types'
55import { Report } from 'ctrf'
66import { readTemplate , reportTypeToInputKey } from '../utils'
77import { BuiltInReports , getBasePath } from '../reports/core'
@@ -17,6 +17,9 @@ import { isAnyReportEnabled } from '../utils/report-utils'
1717 * @param report - The CTRF report to generate views from.
1818 */
1919export function generateViews ( inputs : Inputs , report : Report ) : void {
20+ const hasPreviousResults =
21+ ( ( report . extra ?. previousResults as PreviousResult [ ] ) ?. length ?? 0 ) > 0
22+
2023 if ( inputs . title ) {
2124 core . summary . addHeading ( inputs . title , 2 ) . addEOL ( ) . addEOL ( )
2225 }
@@ -27,8 +30,11 @@ export function generateViews(inputs: Inputs, report: Report): void {
2730 core . info (
2831 'No specific report selected. Generating default reports: summary, failed, flaky, skipped, and tests.'
2932 )
30-
31- addViewToSummary ( '### Summary' , BuiltInReports . SummaryTable , report )
33+ if ( hasPreviousResults === false ) {
34+ addViewToSummary ( '### Summary' , BuiltInReports . SummaryTable , report )
35+ } else {
36+ addViewToSummary ( '### Summary' , BuiltInReports . SummaryDeltaTable , report )
37+ }
3238 if ( reportConditionals ?. showFailedReports ) {
3339 addViewToSummary ( '### Failed Tests' , BuiltInReports . FailedTable , report )
3440 } else {
@@ -196,12 +202,22 @@ function generateReportByType(
196202 inputs : Inputs ,
197203 report : Report
198204) : void {
205+ const hasPreviousResults =
206+ ( ( report . extra ?. previousResults as PreviousResult [ ] ) ?. length ?? 0 ) > 0
199207 const reportConditionals = report . extra
200208 ?. reportConditionals as ReportConditionals
201209 switch ( reportType ) {
202210 case 'summary-report' :
203211 core . info ( 'Adding summary report to summary' )
204- addViewToSummary ( '### Summary' , BuiltInReports . SummaryTable , report )
212+ if ( hasPreviousResults === false ) {
213+ addViewToSummary ( '### Summary' , BuiltInReports . SummaryTable , report )
214+ } else {
215+ addViewToSummary (
216+ '### Summary' ,
217+ BuiltInReports . SummaryDeltaTable ,
218+ report
219+ )
220+ }
205221 break
206222 case 'summary-delta-report' :
207223 core . info ( 'Adding summary delta report to summary' )
0 commit comments