Caching for gradle-build-action was ${listener.cacheStatus} - expand for details
\n`
+ )
+
+ 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 = listener.cacheEntries
.map(
entry =>
`Entry: ${entry.entryName}
@@ -114,43 +134,15 @@ export function logCachingReport(listener: CacheListener): void {
Saved Key : ${entry.savedKey ?? ''}
Size: ${formatSize(entry.savedSize)}
${getSavedMessage(entry, listener.isCacheReadOnly)}
----`
+`
)
- .join('\n')
+ .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)} |
-
-`
- )
-
- if (listener.isCacheReadOnly) {
- core.summary.addRaw('- **Cache is read-only**\n')
- }
- if (listener.isCacheWriteOnly) {
- core.summary.addRaw('- **Cache is write-only**\n')
- }
-
- core.summary.addDetails(
- 'Cache Entry Details',
- `
-
-${entries}
+ core.summary.addRaw(`
+${entryDetails}
-
-`
- )
+
+`)
}
function getRestoredMessage(entry: CacheEntryListener, isCacheWriteOnly: boolean): string {
@@ -189,18 +181,11 @@ function getCount(
return cacheEntries.filter(e => predicate(e) !== undefined).length
}
-function getBytes(
+function getSize(
cacheEntries: CacheEntryListener[],
predicate: (value: CacheEntryListener) => number | undefined
): 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)
+ const bytes = cacheEntries.map(e => predicate(e) ?? 0).reduce((p, v) => p + v, 0)
return Math.round(bytes / (1024 * 1024))
}
diff --git a/src/caches.ts b/src/caches.ts
index 54247cf..b77f8f0 100644
--- a/src/caches.ts
+++ b/src/caches.ts
@@ -19,6 +19,7 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen
core.info('Cache is disabled: will not restore state from previous builds.')
// Initialize the Gradle User Home even when caching is disabled.
gradleStateCache.init()
+ cacheListener.isCacheDisabled = true
return
}
diff --git a/src/job-summary.ts b/src/job-summary.ts
index eba8bed..c5dd440 100644
--- a/src/job-summary.ts
+++ b/src/job-summary.ts
@@ -12,17 +12,15 @@ interface BuildResult {
}
export function writeJobSummary(cacheListener: CacheListener): void {
- core.info('Writing job summary...')
+ core.info('Writing job summary')
const buildResults = loadBuildResults()
if (buildResults.length === 0) {
core.debug('No Gradle build results found. Summary table will not be generated.')
} else {
- core.info('Writing summary table')
writeSummaryTable(buildResults)
}
- core.info('Writing cache report...')
logCachingReport(cacheListener)
core.summary.write()
@@ -43,28 +41,32 @@ function loadBuildResults(): BuildResult[] {
}
function writeSummaryTable(results: BuildResult[]): void {
- core.summary.addRaw('\n')
core.summary.addHeading('Gradle Builds', 3)
- core.summary.addRaw('\n| Root Project | Tasks | Gradle Version | Outcome |\n| - | - | - | - |\n')
- for (const result of results) {
- const tableRow = `| ${result.rootProject} \
- | ${result.requestedTasks} \
- | ${result.gradleVersion} \
- | ${renderOutcome(result)} \
- |\n`
- core.summary.addRaw(tableRow)
- }
+ core.summary.addTable([
+ [
+ {data: 'Root Project', header: true},
+ {data: 'Tasks', header: true},
+ {data: 'Gradle Version', header: true},
+ {data: 'Outcome', header: true}
+ ],
+ ...results.map(result => [
+ result.rootProject,
+ result.requestedTasks,
+ result.gradleVersion,
+ renderOutcome(result)
+ ])
+ ])
core.summary.addRaw('\n')
}
function renderOutcome(result: BuildResult): string {
- if (result.buildScanUri) {
- return `[![Gradle Build](https://img.shields.io/badge/Build%20Scan%E2%84%A2-${
- result.buildFailed ? 'FAILED-red' : 'SUCCESS-brightgreen'
- }?logo=Gradle)](${result.buildScanUri})`
- }
+ const badgeUrl = result.buildFailed
+ ? 'https://img.shields.io/badge/Build%20Scan%E2%84%A2-FAILED-red?logo=Gradle'
+ : 'https://img.shields.io/badge/Build%20Scan%E2%84%A2-SUCCESS-brightgreen?logo=Gradle'
+ const badgeHtml = `