diff --git a/src/cache-reporting.ts b/src/cache-reporting.ts index 0a90800..7f05406 100644 --- a/src/cache-reporting.ts +++ b/src/cache-reporting.ts @@ -1,4 +1,3 @@ -import * as core from '@actions/core' import * as cache from '@actions/cache' /** @@ -112,47 +111,36 @@ export class CacheEntryListener { } } -export function writeCachingReport(listener: CacheListener): void { +export function generateCachingReport(listener: CacheListener): string { const entries = listener.cacheEntries - core.summary.addRaw( - `\n

Caching for gradle-build-action was ${listener.cacheStatus} - expand for details

\n` - ) + return ` +
+

Caching for gradle-build-action was ${listener.cacheStatus} - expand for details

+${renderEntryTable(entries)} - core.summary.addTable([ - [ - {data: '', header: true}, - {data: 'Count', header: true}, - {data: 'Total Size (Mb)', header: true} - ], - ['Entries Restored', `${getCount(entries, e => e.restoredSize)}`, `${getSize(entries, e => e.restoredSize)}`], - ['Entries Saved', `${getCount(entries, e => e.savedSize)}`, `${getSize(entries, e => e.savedSize)}`] - ]) - - core.summary.addHeading('Cache Entry Details', 5) - - const entryDetails = renderEntryDetails(listener) - core.summary.addRaw(`
-${entryDetails}
+
Cache Entry Details
+
+    ${renderEntryDetails(listener)}
 
-`) + ` } -export function logCachingReport(listener: CacheListener): void { - const entries = listener.cacheEntries - - core.startGroup(`Caching for gradle-build-action was ${listener.cacheStatus} - expand for details`) - - core.info( - `Entries Restored: ${getCount(entries, e => e.restoredSize)} (${getSize(entries, e => e.restoredSize)} Mb)` - ) - core.info(`Entries Saved : ${getCount(entries, e => e.savedSize)} (${getSize(entries, e => e.savedSize)} Mb)`) - - core.info(`Cache Entry Details`) - core.info(renderEntryDetails(listener)) - - core.endGroup() +function renderEntryTable(entries: CacheEntryListener[]): string { + return ` + + + + + + + + + + +
CountTotal Size (Mb)
Entries Restored${getCount(entries, e => e.restoredSize)}${getSize(entries, e => e.restoredSize)}
Entries Saved${getCount(entries, e => e.savedSize)}${getSize(entries, e => e.savedSize)}
+ ` } function renderEntryDetails(listener: CacheListener): string { diff --git a/src/job-summary.ts b/src/job-summary.ts index ec3b160..393269b 100644 --- a/src/job-summary.ts +++ b/src/job-summary.ts @@ -1,35 +1,34 @@ import * as core from '@actions/core' +import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary' + +import * as params from './input-params' import {BuildResult} from './build-results' -import {writeCachingReport, CacheListener, logCachingReport} from './cache-reporting' +import {CacheListener, generateCachingReport} from './cache-reporting' -export async function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise { - core.info('Writing job summary') +export async function generateJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise { + const summaryTable = renderSummaryTable(buildResults) + const cachingReport = generateCachingReport(cacheListener) - if (buildResults.length === 0) { - core.debug('No Gradle build results found. Summary table will not be generated.') + if (shouldGenerateJobSummary()) { + core.summary.addRaw(summaryTable) + core.summary.addRaw(cachingReport) + await core.summary.write() } else { - writeSummaryTable(buildResults) + core.info('============================') + core.info(summaryTable) + core.info('============================') + core.info(cachingReport) + core.info('============================') } - - writeCachingReport(cacheListener) - - await core.summary.write() } -export async function logJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise { - if (buildResults.length === 0) { - core.debug('No Gradle build results found. Summary table will not be logged.') - } else { - logSummaryTable(buildResults) +function renderSummaryTable(results: BuildResult[]): string { + if (results.length === 0) { + return 'No Gradle build results detected.' } - logCachingReport(cacheListener) -} - -function writeSummaryTable(results: BuildResult[]): void { - core.summary.addHeading('Gradle Builds', 3) - - core.summary.addRaw(` + return ` +

Gradle Builds

@@ -39,7 +38,7 @@ function writeSummaryTable(results: BuildResult[]): void { ${results.map(result => renderBuildResultRow(result)).join('')}
Root ProjectBuild ScanĀ®
- `) + ` } function renderBuildResultRow(result: BuildResult): string { @@ -77,18 +76,11 @@ function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetU return `${badgeHtml}` } -function logSummaryTable(results: BuildResult[]): void { - core.info('============================') - core.info('Gradle Builds') - core.info('----------------------------') - core.info('Root Project | Requested Tasks | Gradle Version | Build Outcome | Build ScanĀ®') - core.info('----------------------------') - for (const result of results) { - core.info( - `${result.rootProjectName} | ${result.requestedTasks} | ${result.gradleVersion} | ${ - result.buildFailed ? 'FAILED' : 'SUCCESS' - } | ${result.buildScanFailed ? 'Publish failed' : result.buildScanUri}` - ) +function shouldGenerateJobSummary(): boolean { + // Check if Job Summary is supported on this platform + if (!process.env[SUMMARY_ENV_VAR]) { + return false } - core.info('============================') + + return params.isJobSummaryEnabled() } diff --git a/src/setup-gradle.ts b/src/setup-gradle.ts index 1a72597..84ecce7 100644 --- a/src/setup-gradle.ts +++ b/src/setup-gradle.ts @@ -1,14 +1,13 @@ import * as core from '@actions/core' import * as exec from '@actions/exec' -import {SUMMARY_ENV_VAR} from '@actions/core/lib/summary' import * as path from 'path' import * as os from 'os' import * as caches from './caches' import * as layout from './repository-layout' import * as params from './input-params' import * as dependencyGraph from './dependency-graph' +import * as jobSummary from './job-summary' -import {logJobSummary, writeJobSummary} from './job-summary' import {loadBuildResults} from './build-results' import {CacheListener} from './cache-reporting' import {DaemonController} from './daemon-controller' @@ -56,11 +55,7 @@ export async function complete(): Promise { await caches.save(gradleUserHome, cacheListener, daemonController) - if (shouldGenerateJobSummary()) { - await writeJobSummary(buildResults, cacheListener) - } else { - logJobSummary(buildResults, cacheListener) - } + await jobSummary.generateJobSummary(buildResults, cacheListener) await dependencyGraph.complete(params.getDependencyGraphOption()) @@ -93,12 +88,3 @@ async function determineUserHome(): Promise { core.debug(`Determined user.home from java -version output: '${userHome}'`) return userHome } - -function shouldGenerateJobSummary(): boolean { - // Check if Job Summary is supported on this platform - if (!process.env[SUMMARY_ENV_VAR]) { - return false - } - - return params.isJobSummaryEnabled() -}