Add error to job summary

This commit is contained in:
daz 2024-07-22 08:02:03 -06:00
parent fae6382622
commit 1a11891cfe
No known key found for this signature in database
2 changed files with 36 additions and 10 deletions

View File

@ -3,6 +3,7 @@ import {getActionId} from './configuration'
const DEPRECATION_UPGRADE_PAGE = 'https://github.com/gradle/actions/blob/main/docs/deprecation-upgrade-guide.md' const DEPRECATION_UPGRADE_PAGE = 'https://github.com/gradle/actions/blob/main/docs/deprecation-upgrade-guide.md'
const recordedDeprecations: Deprecation[] = [] const recordedDeprecations: Deprecation[] = []
const recordedErrors: string[] = []
export class Deprecation { export class Deprecation {
constructor(readonly message: string) {} constructor(readonly message: string) {}
@ -24,13 +25,19 @@ export function recordDeprecation(message: string): void {
export function failOnUseOfRemovedFeature(removalMessage: string, deprecationMessage: string = removalMessage): void { export function failOnUseOfRemovedFeature(removalMessage: string, deprecationMessage: string = removalMessage): void {
const deprecation = new Deprecation(deprecationMessage) const deprecation = new Deprecation(deprecationMessage)
core.setFailed(`${removalMessage}. See ${deprecation.getDocumentationLink()}`) const errorMessage = `${removalMessage}. See ${deprecation.getDocumentationLink()}`
recordedErrors.push(errorMessage)
core.setFailed(errorMessage)
} }
export function getDeprecations(): Deprecation[] { export function getDeprecations(): Deprecation[] {
return recordedDeprecations return recordedDeprecations
} }
export function getErrors(): string[] {
return recordedErrors
}
export function emitDeprecationWarnings(hasJobSummary = true): void { export function emitDeprecationWarnings(hasJobSummary = true): void {
if (recordedDeprecations.length > 0) { if (recordedDeprecations.length > 0) {
core.warning( core.warning(
@ -43,17 +50,21 @@ export function emitDeprecationWarnings(hasJobSummary = true): void {
} }
export function saveDeprecationState(): void { export function saveDeprecationState(): void {
core.saveState('deprecations', JSON.stringify(recordedDeprecations)) core.saveState('deprecation-collector_deprecations', JSON.stringify(recordedDeprecations))
core.saveState('deprecation-collector_errors', JSON.stringify(recordedErrors))
} }
export function restoreDeprecationState(): void { export function restoreDeprecationState(): void {
const stringRep = core.getState('deprecations') const savedDeprecations = core.getState('deprecation-collector_deprecations')
if (stringRep === '') { if (savedDeprecations) {
return
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
JSON.parse(stringRep).forEach((obj: any) => { JSON.parse(savedDeprecations).forEach((obj: any) => {
recordedDeprecations.push(new Deprecation(obj.message)) recordedDeprecations.push(new Deprecation(obj.message))
}) })
} }
const savedErrors = core.getState('deprecation-collector_errors')
if (savedErrors) {
recordedErrors.push(...JSON.parse(savedErrors))
}
}

View File

@ -4,13 +4,20 @@ import {RequestError} from '@octokit/request-error'
import {BuildResults, BuildResult} from './build-results' import {BuildResults, BuildResult} from './build-results'
import {SummaryConfig, getActionId, getGithubToken} from './configuration' import {SummaryConfig, getActionId, getGithubToken} from './configuration'
import {Deprecation, getDeprecations} from './deprecation-collector' import {Deprecation, getDeprecations, getErrors} from './deprecation-collector'
export async function generateJobSummary( export async function generateJobSummary(
buildResults: BuildResults, buildResults: BuildResults,
cachingReport: string, cachingReport: string,
config: SummaryConfig config: SummaryConfig
): Promise<void> { ): Promise<void> {
const errors = renderErrors()
if (errors) {
core.summary.addRaw(errors)
await core.summary.write()
return
}
const summaryTable = renderSummaryTable(buildResults.results) const summaryTable = renderSummaryTable(buildResults.results)
const hasFailure = buildResults.anyFailed() const hasFailure = buildResults.anyFailed()
@ -82,6 +89,14 @@ export function renderSummaryTable(results: BuildResult[]): string {
return `${renderDeprecations()}\n${renderBuildResults(results)}` return `${renderDeprecations()}\n${renderBuildResults(results)}`
} }
function renderErrors(): string | undefined {
const errors = getErrors()
if (errors.length === 0) {
return undefined
}
return errors.map(error => `<b>:x: ${error}</b>`).join('\n')
}
function renderDeprecations(): string { function renderDeprecations(): string {
const deprecations = getDeprecations() const deprecations = getDeprecations()
if (deprecations.length === 0) { if (deprecations.length === 0) {