Improve rendering of Job Summary

This commit is contained in:
Daz DeBoer 2022-06-19 09:40:27 -06:00
parent 1903bd4674
commit 56036f8577
No known key found for this signature in database
GPG Key ID: DD6B9F0B06683D5D

View File

@ -11,6 +11,7 @@ export interface BuildResult {
get gradleHomeDir(): string get gradleHomeDir(): string
get buildFailed(): boolean get buildFailed(): boolean
get buildScanUri(): string get buildScanUri(): string
get buildScanFailed(): boolean
} }
export async function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise<void> { export async function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise<void> {
@ -48,23 +49,40 @@ function writeSummaryTable(results: BuildResult[]): void {
{data: 'Root Project', header: true}, {data: 'Root Project', header: true},
{data: 'Tasks', header: true}, {data: 'Tasks', header: true},
{data: 'Gradle Version', header: true}, {data: 'Gradle Version', header: true},
{data: 'Outcome', header: true} {data: 'Outcome', header: true},
{data: 'Build Scan™', header: true}
], ],
...results.map(result => [ ...results.map(result => [
result.rootProjectName, result.rootProjectName,
result.requestedTasks, result.requestedTasks,
result.gradleVersion, result.gradleVersion,
renderOutcome(result) renderOutcome(result),
renderBuildScan(result)
]) ])
]) ])
core.summary.addRaw('\n') core.summary.addRaw('\n')
} }
function renderOutcome(result: BuildResult): string { function renderOutcome(result: BuildResult): string {
const labelPart = result.buildScanUri ? 'Build%20Scan%E2%84%A2' : 'Build' return result.buildFailed ? ':x:' : ':white_check_mark:'
const outcomePart = result.buildFailed ? 'FAILED-red' : 'SUCCESS-brightgreen' }
const badgeUrl = `https://img.shields.io/badge/${labelPart}-${outcomePart}?logo=Gradle`
const badgeHtml = `<img src="${badgeUrl}" alt="Gradle Build">` function renderBuildScan(result: BuildResult): string {
const targetUrl = result.buildScanUri ? result.buildScanUri : '#' if (result.buildScanFailed) {
return renderBuildScanBadge(
'PUBLISHED_FAILED',
'orange',
'https://docs.gradle.com/enterprise/gradle-plugin/#troubleshooting'
)
}
if (result.buildScanUri) {
return renderBuildScanBadge('PUBLISHED', '06A0CE', result.buildScanUri)
}
return renderBuildScanBadge('NOT_PUBLISHED', 'lightgrey', 'https://docs.gradle.com/enterprise/gradle-plugin/')
}
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}" />`
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>` return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`
} }