mirror of
https://github.com/gradle/gradle-build-action.git
synced 2025-06-06 16:26:12 +02:00
Allow job-summary only on failure
Instead of a binary true/false option, it is now possible to only add a Job Summary when the build failed. This applies both to the overall Job Summary added to the workflow run, and to the new PR comment feature.
This commit is contained in:
parent
34a07dced0
commit
333078158e
5 changed files with 112 additions and 20 deletions
|
@ -71,12 +71,25 @@ export function isJobSummaryEnabled(): boolean {
|
|||
return getBooleanInput('generate-job-summary', true)
|
||||
}
|
||||
|
||||
export function isPRCommentEnabled(): boolean {
|
||||
return getBooleanInput('add-pr-comment', false)
|
||||
export function getJobSummaryOption(): JobSummaryOption {
|
||||
return parseJobSummaryOption('add-job-summary')
|
||||
}
|
||||
|
||||
export function isDependencyGraphEnabled(): boolean {
|
||||
return getBooleanInput('generate-dependency-graph', true)
|
||||
export function getPRCommentOption(): JobSummaryOption {
|
||||
return parseJobSummaryOption('add-job-summary-as-pr-comment')
|
||||
}
|
||||
|
||||
function parseJobSummaryOption(paramName: string): JobSummaryOption {
|
||||
const val = core.getInput(paramName)
|
||||
switch (val.toLowerCase().trim()) {
|
||||
case 'never':
|
||||
return JobSummaryOption.Never
|
||||
case 'always':
|
||||
return JobSummaryOption.Always
|
||||
case 'on-failure':
|
||||
return JobSummaryOption.OnFailure
|
||||
}
|
||||
throw TypeError(`The value '${val}' is not valid for ${paramName}. Valid values are: [never, always, on-failure].`)
|
||||
}
|
||||
|
||||
export function getDependencyGraphOption(): DependencyGraphOption {
|
||||
|
@ -94,7 +107,7 @@ export function getDependencyGraphOption(): DependencyGraphOption {
|
|||
return DependencyGraphOption.DownloadAndSubmit
|
||||
}
|
||||
throw TypeError(
|
||||
`The value '${val} is not valid for 'dependency-graph. Valid values are: [disabled, generate, generate-and-submit, generate-and-upload, download-and-submit]. The default value is 'disabled'.`
|
||||
`The value '${val}' is not valid for 'dependency-graph'. Valid values are: [disabled, generate, generate-and-submit, generate-and-upload, download-and-submit]. The default value is 'disabled'.`
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -135,3 +148,9 @@ export enum DependencyGraphOption {
|
|||
GenerateAndUpload = 'generate-and-upload',
|
||||
DownloadAndSubmit = 'download-and-submit'
|
||||
}
|
||||
|
||||
export enum JobSummaryOption {
|
||||
Never = 'never',
|
||||
Always = 'always',
|
||||
OnFailure = 'on-failure'
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ export async function generateJobSummary(buildResults: BuildResult[], cacheListe
|
|||
const summaryTable = renderSummaryTable(buildResults)
|
||||
const cachingReport = generateCachingReport(cacheListener)
|
||||
|
||||
if (shouldGenerateJobSummary()) {
|
||||
if (shouldGenerateJobSummary(buildResults)) {
|
||||
core.info('Generating Job Summary')
|
||||
|
||||
core.summary.addRaw(summaryTable)
|
||||
|
@ -24,7 +24,7 @@ export async function generateJobSummary(buildResults: BuildResult[], cacheListe
|
|||
core.info('============================')
|
||||
}
|
||||
|
||||
if (shouldAddPRComment()) {
|
||||
if (shouldAddPRComment(buildResults)) {
|
||||
await addPRComment(summaryTable)
|
||||
}
|
||||
}
|
||||
|
@ -111,15 +111,32 @@ function renderBuildScanBadge(outcomeText: string, outcomeColor: string, targetU
|
|||
return `<a href="${targetUrl}" rel="nofollow">${badgeHtml}</a>`
|
||||
}
|
||||
|
||||
function shouldGenerateJobSummary(): boolean {
|
||||
function shouldGenerateJobSummary(buildResults: BuildResult[]): boolean {
|
||||
// Check if Job Summary is supported on this platform
|
||||
if (!process.env[SUMMARY_ENV_VAR]) {
|
||||
return false
|
||||
}
|
||||
|
||||
return params.isJobSummaryEnabled()
|
||||
// Check if Job Summary is disabled using the deprecated input
|
||||
if (!params.isJobSummaryEnabled()) {
|
||||
return false
|
||||
}
|
||||
|
||||
return shouldAddJobSummary(params.getJobSummaryOption(), buildResults)
|
||||
}
|
||||
|
||||
function shouldAddPRComment(): boolean {
|
||||
return params.isPRCommentEnabled()
|
||||
function shouldAddPRComment(buildResults: BuildResult[]): boolean {
|
||||
return shouldAddJobSummary(params.getPRCommentOption(), buildResults)
|
||||
}
|
||||
|
||||
function shouldAddJobSummary(option: params.JobSummaryOption, buildResults: BuildResult[]): boolean {
|
||||
switch (option) {
|
||||
case params.JobSummaryOption.Always:
|
||||
return true
|
||||
case params.JobSummaryOption.Never:
|
||||
return false
|
||||
case params.JobSummaryOption.OnFailure:
|
||||
core.info(`Got these build results: ${JSON.stringify(buildResults)}`)
|
||||
return buildResults.some(result => result.buildFailed)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue