Write job summary to logs when feature not available

This commit is contained in:
Daz DeBoer
2022-06-20 17:53:30 -06:00
parent ec939a8c10
commit eaed5520c4
3 changed files with 60 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
import * as core from '@actions/core'
import fs from 'fs'
import path from 'path'
import {logCachingReport, CacheListener} from './cache-reporting'
import {writeCachingReport, CacheListener, logCachingReport} from './cache-reporting'
export interface BuildResult {
get rootProjectName(): string
@@ -23,11 +23,21 @@ export async function writeJobSummary(buildResults: BuildResult[], cacheListener
writeSummaryTable(buildResults)
}
logCachingReport(cacheListener)
writeCachingReport(cacheListener)
await core.summary.write()
}
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)
}
export function loadBuildResults(): BuildResult[] {
const buildResultsDir = path.resolve(process.env['RUNNER_TEMP']!, '.build-results')
if (!fs.existsSync(buildResultsDir)) {
@@ -92,3 +102,19 @@ function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetU
const badgeHtml = `<img src="${badgeUrl}" alt="Build Scan ${outcomeText}" />`
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`
}
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('============================')
}