2022-06-02 12:57:35 -06:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
2022-06-02 22:39:09 -06:00
|
|
|
import {logCachingReport, CacheListener} from './cache-reporting'
|
2022-06-02 12:57:35 -06:00
|
|
|
|
2022-06-05 08:34:07 -06:00
|
|
|
export interface BuildResult {
|
2022-06-05 08:18:25 -06:00
|
|
|
get rootProjectName(): string
|
|
|
|
get rootProjectDir(): string
|
2022-06-02 12:57:35 -06:00
|
|
|
get requestedTasks(): string
|
|
|
|
get gradleVersion(): string
|
2022-06-05 08:18:25 -06:00
|
|
|
get gradleHomeDir(): string
|
2022-06-02 12:57:35 -06:00
|
|
|
get buildFailed(): boolean
|
|
|
|
get buildScanUri(): string
|
|
|
|
}
|
|
|
|
|
2022-06-09 09:06:27 -06:00
|
|
|
export async function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): Promise<void> {
|
2022-06-04 09:36:41 -06:00
|
|
|
core.info('Writing job summary')
|
2022-06-02 22:39:09 -06:00
|
|
|
|
2022-06-02 12:57:35 -06:00
|
|
|
if (buildResults.length === 0) {
|
|
|
|
core.debug('No Gradle build results found. Summary table will not be generated.')
|
|
|
|
} else {
|
|
|
|
writeSummaryTable(buildResults)
|
|
|
|
}
|
2022-06-02 22:39:09 -06:00
|
|
|
|
|
|
|
logCachingReport(cacheListener)
|
|
|
|
|
2022-06-09 09:06:27 -06:00
|
|
|
await core.summary.write()
|
2022-06-02 12:57:35 -06:00
|
|
|
}
|
|
|
|
|
2022-06-05 08:34:07 -06:00
|
|
|
export function loadBuildResults(): BuildResult[] {
|
2022-06-02 12:57:35 -06: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 14:21:10 -06:00
|
|
|
core.summary.addHeading('Gradle Builds', 3)
|
2022-06-04 09:36:41 -06:00
|
|
|
core.summary.addTable([
|
|
|
|
[
|
|
|
|
{data: 'Root Project', header: true},
|
|
|
|
{data: 'Tasks', header: true},
|
|
|
|
{data: 'Gradle Version', header: true},
|
|
|
|
{data: 'Outcome', header: true}
|
|
|
|
],
|
|
|
|
...results.map(result => [
|
2022-06-05 08:18:25 -06:00
|
|
|
result.rootProjectName,
|
2022-06-04 09:36:41 -06:00
|
|
|
result.requestedTasks,
|
|
|
|
result.gradleVersion,
|
|
|
|
renderOutcome(result)
|
|
|
|
])
|
|
|
|
])
|
2022-06-02 22:39:09 -06:00
|
|
|
core.summary.addRaw('\n')
|
2022-06-02 12:57:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderOutcome(result: BuildResult): string {
|
2022-06-04 23:10:32 -06:00
|
|
|
const labelPart = result.buildScanUri ? 'Build%20Scan%E2%84%A2' : 'Build'
|
|
|
|
const outcomePart = result.buildFailed ? 'FAILED-red' : 'SUCCESS-brightgreen'
|
|
|
|
const badgeUrl = `https://img.shields.io/badge/${labelPart}-${outcomePart}?logo=Gradle`
|
2022-06-04 09:36:41 -06:00
|
|
|
const badgeHtml = `<img src="${badgeUrl}" alt="Gradle Build">`
|
2022-06-04 23:10:32 -06:00
|
|
|
const targetUrl = result.buildScanUri ? result.buildScanUri : '#'
|
|
|
|
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`
|
2022-06-02 12:57:35 -06:00
|
|
|
}
|