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
|
|
|
|
|
|
|
interface BuildResult {
|
|
|
|
get rootProject(): string
|
|
|
|
get requestedTasks(): string
|
|
|
|
get gradleVersion(): string
|
|
|
|
get buildFailed(): boolean
|
|
|
|
get buildScanUri(): string
|
|
|
|
}
|
|
|
|
|
2022-06-02 22:39:09 -06:00
|
|
|
export function writeJobSummary(cacheListener: CacheListener): void {
|
|
|
|
core.info('Writing job summary...')
|
|
|
|
|
2022-06-02 12:57:35 -06:00
|
|
|
const buildResults = loadBuildResults()
|
|
|
|
if (buildResults.length === 0) {
|
|
|
|
core.debug('No Gradle build results found. Summary table will not be generated.')
|
|
|
|
} else {
|
2022-06-02 22:39:09 -06:00
|
|
|
core.info('Writing summary table')
|
2022-06-02 12:57:35 -06:00
|
|
|
writeSummaryTable(buildResults)
|
|
|
|
}
|
2022-06-02 22:39:09 -06:00
|
|
|
|
|
|
|
core.info('Writing cache report...')
|
|
|
|
logCachingReport(cacheListener)
|
|
|
|
|
|
|
|
core.summary.write()
|
2022-06-02 12:57:35 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadBuildResults(): BuildResult[] {
|
|
|
|
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 22:39:09 -06:00
|
|
|
core.summary.addRaw('\n')
|
2022-06-02 14:21:10 -06:00
|
|
|
core.summary.addHeading('Gradle Builds', 3)
|
2022-06-02 22:39:09 -06:00
|
|
|
core.summary.addRaw('\n| Root Project | Tasks | Gradle Version | Outcome |\n| - | - | - | - |\n')
|
2022-06-02 12:57:35 -06:00
|
|
|
for (const result of results) {
|
|
|
|
const tableRow = `| ${result.rootProject} \
|
|
|
|
| ${result.requestedTasks} \
|
|
|
|
| ${result.gradleVersion} \
|
|
|
|
| ${renderOutcome(result)} \
|
|
|
|
|\n`
|
|
|
|
core.summary.addRaw(tableRow)
|
|
|
|
}
|
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 {
|
|
|
|
if (result.buildScanUri) {
|
|
|
|
return `[](${result.buildScanUri})`
|
|
|
|
}
|
|
|
|
|
|
|
|
return ``
|
|
|
|
}
|