2022-06-02 18:57:35 +00:00
|
|
|
import * as core from '@actions/core'
|
2022-06-22 22:35:55 +00:00
|
|
|
import {BuildResult} from './build-results'
|
2022-06-20 23:53:30 +00:00
|
|
|
import {writeCachingReport, CacheListener, logCachingReport} from './cache-reporting'
|
2022-06-02 18:57:35 +00:00
|
|
|
|
2022-06-09 15:06:27 +00:00
|
|
|
export async function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise<void> {
|
2022-06-04 15:36:41 +00:00
|
|
|
core.info('Writing job summary')
|
2022-06-03 04:39:09 +00:00
|
|
|
|
2022-06-02 18:57:35 +00:00
|
|
|
if (buildResults.length === 0) {
|
|
|
|
core.debug('No Gradle build results found. Summary table will not be generated.')
|
|
|
|
} else {
|
|
|
|
writeSummaryTable(buildResults)
|
|
|
|
}
|
2022-06-03 04:39:09 +00:00
|
|
|
|
2022-06-20 23:53:30 +00:00
|
|
|
writeCachingReport(cacheListener)
|
2022-06-03 04:39:09 +00:00
|
|
|
|
2022-06-09 15:06:27 +00:00
|
|
|
await core.summary.write()
|
2022-06-02 18:57:35 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 23:53:30 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-06-02 18:57:35 +00:00
|
|
|
function writeSummaryTable(results: BuildResult[]): void {
|
2022-06-02 20:21:10 +00:00
|
|
|
core.summary.addHeading('Gradle Builds', 3)
|
2022-06-19 15:56:40 +00:00
|
|
|
|
|
|
|
core.summary.addRaw(`
|
|
|
|
<table>
|
|
|
|
<tr>
|
|
|
|
<th>Root Project</th>
|
|
|
|
<th>Requested Tasks</th>
|
|
|
|
<th>Gradle Version</th>
|
|
|
|
<th>Build Outcome</th>
|
|
|
|
<th>Build Scan™</th>
|
|
|
|
</tr>${results.map(result => renderBuildResultRow(result)).join('')}
|
|
|
|
</table>
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderBuildResultRow(result: BuildResult): string {
|
|
|
|
return `
|
|
|
|
<tr>
|
|
|
|
<td>${result.rootProjectName}</td>
|
|
|
|
<td>${result.requestedTasks}</td>
|
|
|
|
<td align='center'>${result.gradleVersion}</td>
|
|
|
|
<td align='center'>${renderOutcome(result)}</td>
|
|
|
|
<td>${renderBuildScan(result)}</td>
|
|
|
|
</tr>`
|
2022-06-02 18:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderOutcome(result: BuildResult): string {
|
2022-06-19 15:40:27 +00:00
|
|
|
return result.buildFailed ? ':x:' : ':white_check_mark:'
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderBuildScan(result: BuildResult): string {
|
|
|
|
if (result.buildScanFailed) {
|
|
|
|
return renderBuildScanBadge(
|
2022-06-19 15:56:40 +00:00
|
|
|
'PUBLISH_FAILED',
|
2022-06-19 15:40:27 +00:00
|
|
|
'orange',
|
|
|
|
'https://docs.gradle.com/enterprise/gradle-plugin/#troubleshooting'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if (result.buildScanUri) {
|
|
|
|
return renderBuildScanBadge('PUBLISHED', '06A0CE', result.buildScanUri)
|
|
|
|
}
|
2022-06-19 15:56:40 +00:00
|
|
|
return renderBuildScanBadge('NOT_PUBLISHED', 'lightgrey', 'https://scans.gradle.com')
|
2022-06-19 15:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetUrl: string): string {
|
|
|
|
const badgeUrl = `https://img.shields.io/badge/Build%20Scan%E2%84%A2-${outcomeText}-${outcomeColor}?logo=Gradle`
|
|
|
|
const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />`
|
2022-06-05 05:10:32 +00:00
|
|
|
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`
|
2022-06-02 18:57:35 +00:00
|
|
|
}
|
2022-06-20 23:53:30 +00:00
|
|
|
|
|
|
|
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('============================')
|
|
|
|
}
|