From 1a11891cfe35cf424c9bcc5612c713047adf3cc4 Mon Sep 17 00:00:00 2001 From: daz Date: Mon, 22 Jul 2024 08:02:03 -0600 Subject: [PATCH] Add error to job summary --- sources/src/deprecation-collector.ts | 29 +++++++++++++++++++--------- sources/src/job-summary.ts | 17 +++++++++++++++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/sources/src/deprecation-collector.ts b/sources/src/deprecation-collector.ts index b0b1c9d..2ef0e8e 100644 --- a/sources/src/deprecation-collector.ts +++ b/sources/src/deprecation-collector.ts @@ -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 recordedDeprecations: Deprecation[] = [] +const recordedErrors: string[] = [] export class Deprecation { constructor(readonly message: string) {} @@ -24,13 +25,19 @@ export function recordDeprecation(message: string): void { export function failOnUseOfRemovedFeature(removalMessage: string, deprecationMessage: string = removalMessage): void { 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[] { return recordedDeprecations } +export function getErrors(): string[] { + return recordedErrors +} + export function emitDeprecationWarnings(hasJobSummary = true): void { if (recordedDeprecations.length > 0) { core.warning( @@ -43,17 +50,21 @@ export function emitDeprecationWarnings(hasJobSummary = true): 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 { - const stringRep = core.getState('deprecations') - if (stringRep === '') { - return + const savedDeprecations = core.getState('deprecation-collector_deprecations') + if (savedDeprecations) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + JSON.parse(savedDeprecations).forEach((obj: any) => { + recordedDeprecations.push(new Deprecation(obj.message)) + }) } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - JSON.parse(stringRep).forEach((obj: any) => { - recordedDeprecations.push(new Deprecation(obj.message)) - }) + const savedErrors = core.getState('deprecation-collector_errors') + if (savedErrors) { + recordedErrors.push(...JSON.parse(savedErrors)) + } } diff --git a/sources/src/job-summary.ts b/sources/src/job-summary.ts index 628dbab..a1646fa 100644 --- a/sources/src/job-summary.ts +++ b/sources/src/job-summary.ts @@ -4,13 +4,20 @@ import {RequestError} from '@octokit/request-error' import {BuildResults, BuildResult} from './build-results' import {SummaryConfig, getActionId, getGithubToken} from './configuration' -import {Deprecation, getDeprecations} from './deprecation-collector' +import {Deprecation, getDeprecations, getErrors} from './deprecation-collector' export async function generateJobSummary( buildResults: BuildResults, cachingReport: string, config: SummaryConfig ): Promise { + const errors = renderErrors() + if (errors) { + core.summary.addRaw(errors) + await core.summary.write() + return + } + const summaryTable = renderSummaryTable(buildResults.results) const hasFailure = buildResults.anyFailed() @@ -82,6 +89,14 @@ export function renderSummaryTable(results: BuildResult[]): string { return `${renderDeprecations()}\n${renderBuildResults(results)}` } +function renderErrors(): string | undefined { + const errors = getErrors() + if (errors.length === 0) { + return undefined + } + return errors.map(error => `:x: ${error}`).join('\n') +} + function renderDeprecations(): string { const deprecations = getDeprecations() if (deprecations.length === 0) {