From f9c8fcf79f0d620f989609f93765819b3e7ffdaf Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Thu, 2 Jun 2022 14:21:10 -0600 Subject: [PATCH] Adding caching details to Job Summary --- src/cache-reporting.ts | 64 +++++++++++++++++++++++++++++++----------- src/job-summary.ts | 1 + 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/cache-reporting.ts b/src/cache-reporting.ts index 10c7d83..767c13e 100644 --- a/src/cache-reporting.ts +++ b/src/cache-reporting.ts @@ -92,22 +92,47 @@ export function logCachingReport(listener: CacheListener): void { return } - core.info(`---------- Caching Summary ------------- -Restored Entries Count: ${getCount(listener.cacheEntries, e => e.restoredSize)} - Size: ${getSum(listener.cacheEntries, e => e.restoredSize)} -Saved Entries Count: ${getCount(listener.cacheEntries, e => e.savedSize)} - Size: ${getSum(listener.cacheEntries, e => e.savedSize)}`) + core.summary.addHeading('Caching Summary') - core.startGroup('Cache Entry details') - for (const entry of listener.cacheEntries) { - core.info(`Entry: ${entry.entryName} + const entries = listener.cacheEntries + .map( + entry => + `Entry: ${entry.entryName} Requested Key : ${entry.requestedKey ?? ''} Restored Key : ${entry.restoredKey ?? ''} Size: ${formatSize(entry.restoredSize)} Saved Key : ${entry.savedKey ?? ''} - Size: ${formatSize(entry.savedSize)}`) - } - core.endGroup() + Size: ${formatSize(entry.savedSize)}` + ) + .join('\n') + + core.summary.addRaw( + ` + +| | Count | Size (Mb) | Size (B) | +| - | -: | -: | -: | +| Restored | ${getCount(listener.cacheEntries, e => e.restoredSize)} | ${getMegaBytes( + listener.cacheEntries, + e => e.restoredSize + )} | ${getBytes(listener.cacheEntries, e => e.restoredSize)} | +| Saved | ${getCount(listener.cacheEntries, e => e.savedSize)} | ${getMegaBytes( + listener.cacheEntries, + e => e.savedSize + )} | ${getBytes(listener.cacheEntries, e => e.savedSize)} | + +` + ) + + core.summary.addDetails( + 'Cache Entry Details', + ` +
+${entries}
+
+` + ) + + core.summary.write() } function getCount( @@ -117,14 +142,19 @@ function getCount( return cacheEntries.filter(e => predicate(e) !== undefined).length } -function getSum( +function getBytes( cacheEntries: CacheEntryListener[], predicate: (value: CacheEntryListener) => number | undefined -): string { - if (cacheEntries.length === 0) { - return '0' - } - return formatSize(cacheEntries.map(e => predicate(e) ?? 0).reduce((p, v) => p + v, 0)) +): number { + return cacheEntries.map(e => predicate(e) ?? 0).reduce((p, v) => p + v, 0) +} + +function getMegaBytes( + cacheEntries: CacheEntryListener[], + predicate: (value: CacheEntryListener) => number | undefined +): number { + const bytes = getBytes(cacheEntries, predicate) + return Math.round(bytes / (1024 * 1024)) } function formatSize(bytes: number | undefined): string { diff --git a/src/job-summary.ts b/src/job-summary.ts index 314aace..709c462 100644 --- a/src/job-summary.ts +++ b/src/job-summary.ts @@ -34,6 +34,7 @@ function loadBuildResults(): BuildResult[] { } function writeSummaryTable(results: BuildResult[]): void { + core.summary.addHeading('Gradle Builds', 3) core.summary.addRaw(`| Root Project | Tasks | Gradle Version | Outcome |\n| - | - | - | - |\n`) for (const result of results) { const tableRow = `| ${result.rootProject} \