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
}
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',
`
<pre>
${entries}
</pre>
`
)
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'
): number {
return cacheEntries.map(e => predicate(e) ?? 0).reduce((p, v) => p + v, 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 {

View file

@ -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} \