2022-06-02 14:57:35 -04:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
2022-06-03 00:39:09 -04:00
|
|
|
import {logCachingReport, CacheListener} from './cache-reporting'
|
2022-06-02 14:57:35 -04:00
|
|
|
|
2022-06-05 10:34:07 -04:00
|
|
|
export interface BuildResult {
|
2022-06-05 10:18:25 -04:00
|
|
|
get rootProjectName(): string
|
|
|
|
get rootProjectDir(): string
|
2022-06-02 14:57:35 -04:00
|
|
|
get requestedTasks(): string
|
|
|
|
get gradleVersion(): string
|
2022-06-05 10:18:25 -04:00
|
|
|
get gradleHomeDir(): string
|
2022-06-02 14:57:35 -04:00
|
|
|
get buildFailed(): boolean
|
|
|
|
get buildScanUri(): string
|
2022-06-19 11:40:27 -04:00
|
|
|
get buildScanFailed(): boolean
|
2022-06-02 14:57:35 -04:00
|
|
|
}
|
|
|
|
|
2022-06-09 11:06:27 -04:00
|
|
|
export async function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise<void> {
|
2022-06-04 11:36:41 -04:00
|
|
|
core.info('Writing job summary')
|
2022-06-03 00:39:09 -04:00
|
|
|
|
2022-06-02 14:57:35 -04:00
|
|
|
if (buildResults.length === 0) {
|
|
|
|
core.debug('No Gradle build results found. Summary table will not be generated.')
|
|
|
|
} else {
|
|
|
|
writeSummaryTable(buildResults)
|
|
|
|
}
|
2022-06-03 00:39:09 -04:00
|
|
|
|
|
|
|
logCachingReport(cacheListener)
|
|
|
|
|
2022-06-09 11:06:27 -04:00
|
|
|
await core.summary.write()
|
2022-06-02 14:57:35 -04:00
|
|
|
}
|
|
|
|
|
2022-06-05 10:34:07 -04:00
|
|
|
export function loadBuildResults(): BuildResult[] {
|
2022-06-02 14:57:35 -04:00
|
|
|
const buildResultsDir = path.resolve(process.env['RUNNER_TEMP']!, '.build-results')
|
|
|
|
if (!fs.existsSync(buildResultsDir)) {
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
|
|
|
|
return fs.readdirSync(buildResultsDir).map(file => {
|
|
|
|
// Every file in the .build-results dir should be a BuildResults JSON
|
|
|
|
const filePath = path.join(buildResultsDir, file)
|
|
|
|
const content = fs.readFileSync(filePath, 'utf8')
|
|
|
|
return JSON.parse(content) as BuildResult
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function writeSummaryTable(results: BuildResult[]): void {
|
2022-06-02 16:21:10 -04:00
|
|
|
core.summary.addHeading('Gradle Builds', 3)
|
2022-06-04 11:36:41 -04:00
|
|
|
core.summary.addTable([
|
|
|
|
[
|
|
|
|
{data: 'Root Project', header: true},
|
|
|
|
{data: 'Tasks', header: true},
|
|
|
|
{data: 'Gradle Version', header: true},
|
2022-06-19 11:40:27 -04:00
|
|
|
{data: 'Outcome', header: true},
|
|
|
|
{data: 'Build Scan™', header: true}
|
2022-06-04 11:36:41 -04:00
|
|
|
],
|
|
|
|
...results.map(result => [
|
2022-06-05 10:18:25 -04:00
|
|
|
result.rootProjectName,
|
2022-06-04 11:36:41 -04:00
|
|
|
result.requestedTasks,
|
|
|
|
result.gradleVersion,
|
2022-06-19 11:40:27 -04:00
|
|
|
renderOutcome(result),
|
|
|
|
renderBuildScan(result)
|
2022-06-04 11:36:41 -04:00
|
|
|
])
|
|
|
|
])
|
2022-06-03 00:39:09 -04:00
|
|
|
core.summary.addRaw('\n')
|
2022-06-02 14:57:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderOutcome(result: BuildResult): string {
|
2022-06-19 11:40:27 -04:00
|
|
|
return result.buildFailed ? ':x:' : ':white_check_mark:'
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderBuildScan(result: BuildResult): string {
|
|
|
|
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}" />`
|
2022-06-05 01:10:32 -04:00
|
|
|
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`
|
2022-06-02 14:57:35 -04:00
|
|
|
}
|