Adding caching details to Job Summary

This commit is contained in:
Daz DeBoer 2022-06-02 14:21:10 -06:00
parent 86e82987ba
commit f9c8fcf79f
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
2 changed files with 48 additions and 17 deletions

View file

@ -92,22 +92,47 @@ export function logCachingReport(listener: CacheListener): void {
return return
} }
core.info(`---------- Caching Summary ------------- core.summary.addHeading('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.startGroup('Cache Entry details') const entries = listener.cacheEntries
for (const entry of listener.cacheEntries) { .map(
core.info(`Entry: ${entry.entryName} entry =>
`Entry: ${entry.entryName}
Requested Key : ${entry.requestedKey ?? ''} Requested Key : ${entry.requestedKey ?? ''}
Restored Key : ${entry.restoredKey ?? ''} Restored Key : ${entry.restoredKey ?? ''}
Size: ${formatSize(entry.restoredSize)} Size: ${formatSize(entry.restoredSize)}
Saved Key : ${entry.savedKey ?? ''} Saved Key : ${entry.savedKey ?? ''}
Size: ${formatSize(entry.savedSize)}`) Size: ${formatSize(entry.savedSize)}`
} )
core.endGroup() .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',
`
<pre>
${entries}
</pre>
`
)
core.summary.write()
} }
function getCount( function getCount(
@ -117,14 +142,19 @@ function getCount(
return cacheEntries.filter(e => predicate(e) !== undefined).length return cacheEntries.filter(e => predicate(e) !== undefined).length
} }
function getSum( function getBytes(
cacheEntries: CacheEntryListener[], cacheEntries: CacheEntryListener[],
predicate: (value: CacheEntryListener) => number | undefined predicate: (value: CacheEntryListener) => number | undefined
): string { ): number {
if (cacheEntries.length === 0) { return cacheEntries.map(e => predicate(e) ?? 0).reduce((p, v) => p + v, 0)
return '0'
} }
return formatSize(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 { function formatSize(bytes: number | undefined): string {

View file

@ -34,6 +34,7 @@ function loadBuildResults(): BuildResult[] {
} }
function writeSummaryTable(results: BuildResult[]): void { function writeSummaryTable(results: BuildResult[]): void {
core.summary.addHeading('Gradle Builds', 3)
core.summary.addRaw(`| Root Project | Tasks | Gradle Version | Outcome |\n| - | - | - | - |\n`) core.summary.addRaw(`| Root Project | Tasks | Gradle Version | Outcome |\n| - | - | - | - |\n`)
for (const result of results) { for (const result of results) {
const tableRow = `| ${result.rootProject} \ const tableRow = `| ${result.rootProject} \