mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-12-27 01:02:11 -05:00
Write job summary to logs when feature not available
This commit is contained in:
parent
ec939a8c10
commit
eaed5520c4
3 changed files with 60 additions and 14 deletions
|
@ -104,7 +104,7 @@ export class CacheEntryListener {
|
|||
}
|
||||
}
|
||||
|
||||
export function logCachingReport(listener: CacheListener): void {
|
||||
export function writeCachingReport(listener: CacheListener): void {
|
||||
const entries = listener.cacheEntries
|
||||
|
||||
core.summary.addRaw(
|
||||
|
@ -123,10 +123,34 @@ export function logCachingReport(listener: CacheListener): void {
|
|||
|
||||
core.summary.addHeading('Cache Entry Details', 5)
|
||||
|
||||
const entryDetails = listener.cacheEntries
|
||||
const entryDetails = renderEntryDetails(listener)
|
||||
core.summary.addRaw(`<pre>
|
||||
${entryDetails}
|
||||
</pre>
|
||||
</details>
|
||||
`)
|
||||
}
|
||||
|
||||
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 renderEntryDetails(listener: CacheListener): string {
|
||||
return listener.cacheEntries
|
||||
.map(
|
||||
entry =>
|
||||
`Entry: ${entry.entryName}
|
||||
entry => `Entry: ${entry.entryName}
|
||||
Requested Key : ${entry.requestedKey ?? ''}
|
||||
Restored Key : ${entry.restoredKey ?? ''}
|
||||
Size: ${formatSize(entry.restoredSize)}
|
||||
|
@ -137,12 +161,6 @@ export function logCachingReport(listener: CacheListener): void {
|
|||
`
|
||||
)
|
||||
.join('---\n')
|
||||
|
||||
core.summary.addRaw(`<pre>
|
||||
${entryDetails}
|
||||
</pre>
|
||||
</details>
|
||||
`)
|
||||
}
|
||||
|
||||
function getRestoredMessage(entry: CacheEntryListener, isCacheWriteOnly: boolean): string {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as core from '@actions/core'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import {logCachingReport, CacheListener} from './cache-reporting'
|
||||
import {writeCachingReport, CacheListener, logCachingReport} from './cache-reporting'
|
||||
|
||||
export interface BuildResult {
|
||||
get rootProjectName(): string
|
||||
|
@ -23,11 +23,21 @@ export async function writeJobSummary(buildResults: BuildResult[], cacheListener
|
|||
writeSummaryTable(buildResults)
|
||||
}
|
||||
|
||||
logCachingReport(cacheListener)
|
||||
writeCachingReport(cacheListener)
|
||||
|
||||
await core.summary.write()
|
||||
}
|
||||
|
||||
export async function logJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise<void> {
|
||||
if (buildResults.length === 0) {
|
||||
core.debug('No Gradle build results found. Summary table will not be logged.')
|
||||
} else {
|
||||
logSummaryTable(buildResults)
|
||||
}
|
||||
|
||||
logCachingReport(cacheListener)
|
||||
}
|
||||
|
||||
export function loadBuildResults(): BuildResult[] {
|
||||
const buildResultsDir = path.resolve(process.env['RUNNER_TEMP']!, '.build-results')
|
||||
if (!fs.existsSync(buildResultsDir)) {
|
||||
|
@ -92,3 +102,19 @@ function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetU
|
|||
const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />`
|
||||
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`
|
||||
}
|
||||
|
||||
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}`
|
||||
)
|
||||
}
|
||||
core.info('============================')
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import * as os from 'os'
|
|||
import * as caches from './caches'
|
||||
|
||||
import {CacheListener} from './cache-reporting'
|
||||
import {BuildResult, loadBuildResults, writeJobSummary} from './job-summary'
|
||||
import {BuildResult, loadBuildResults, logJobSummary, writeJobSummary} from './job-summary'
|
||||
|
||||
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED'
|
||||
const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
|
||||
|
@ -63,7 +63,9 @@ export async function complete(): Promise<void> {
|
|||
await caches.save(gradleUserHome, cacheListener)
|
||||
|
||||
if (shouldGenerateJobSummary()) {
|
||||
writeJobSummary(buildResults, cacheListener)
|
||||
await writeJobSummary(buildResults, cacheListener)
|
||||
} else {
|
||||
logJobSummary(buildResults, cacheListener)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue