diff --git a/__tests__/fakes.ts b/__tests__/fakes.ts index 7aa7feb..6def3fb 100644 --- a/__tests__/fakes.ts +++ b/__tests__/fakes.ts @@ -63,8 +63,12 @@ export class FakeDependencies implements Dependencies { } uploadArtifactCallHistory: { artifactName: string; artifactFiles: string[] }[] = [] + uploadArtifactCallback: (() => Promise) | undefined = undefined async uploadArtifact(artifactName: string, artifactFiles: string[]): Promise { this.uploadArtifactCallHistory.push({ artifactName, artifactFiles }) + if (this.uploadArtifactCallback) { + return this.uploadArtifactCallback() + } return Promise.resolve() } diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 0cc396d..fd29cb9 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -321,6 +321,40 @@ describe('main run Tests', () => { }) }) + it('When artifact upload fails with GHES error, action warns and continues', async () => { + dependencies.uploadArtifactCallback = async () => { + throw new Error( + 'GHESNotSupportedError: @actions/artifact v2.0.0+, upload-artifact@v4+ and download-artifact@v4+ are not currently supported on GHES.' + ) + } + await main.run(dependencies, commandExecutor, resultsFactory, summarizer) + + // Should have warned about GHES + expect(dependencies.warnCallHistory).toHaveLength(1) + expect(dependencies.warnCallHistory[0].warnMessage).toEqual(MESSAGES.ARTIFACT_UPLOAD_SKIPPED_GHES) + + // Should NOT have failed — the action should continue + expect(dependencies.failCallHistory).toHaveLength(0) + + // Should still have analyzed results and created summary + expect(resultsFactory.createResultsCallHistory).toHaveLength(1) + expect(dependencies.writeSummaryCallHistory).toHaveLength(1) + }) + + it('When artifact upload fails with non-GHES error, action fails', async () => { + dependencies.uploadArtifactCallback = async () => { + throw new Error('Some other upload error') + } + await main.run(dependencies, commandExecutor, resultsFactory, summarizer) + + // Should have failed with unexpected error + expect(dependencies.failCallHistory).toHaveLength(1) + expect(dependencies.failCallHistory[0].failMessage).toContain('Some other upload error') + + // Should NOT have warned about GHES + expect(dependencies.warnCallHistory).toHaveLength(0) + }) + it('Test nonzero exit code with stderr not containing error from command call', async () => { commandExecutor.runCodeAnalyzerReturnValue = { exitCode: 987, stdout: '', stderr: 'just some warning' } await main.run(dependencies, commandExecutor, resultsFactory, summarizer) diff --git a/dist/index.js b/dist/index.js index 5cdeba0..e1743dd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -105946,7 +105946,9 @@ exports.MESSAGES = { CODE_ANALYZER_FAILED: 'Salesforce Code Analyzer failed.', UNEXPECTED_ERROR: `An unexpected error was thrown (see below). First check to make sure you're providing valid ` + `inputs. If you can't resolve the error, then create an issue at ` + - `https://github.com/forcedotcom/run-code-analyzer/issues.` + `https://github.com/forcedotcom/run-code-analyzer/issues.`, + ARTIFACT_UPLOAD_SKIPPED_GHES: `Artifact upload is not supported on GitHub Enterprise Server. Skipping artifact upload. ` + + `All other results (violation counts, job summary, and pull request review) are still available.` }; exports.MESSAGE_FCNS = { PLUGIN_FOUND: (pluginName, pluginVersion) => `Found version ${pluginVersion} of the ${pluginName} plugin installed.`, @@ -106201,7 +106203,17 @@ async function run(dependencies, commandExecutor, resultsFactory, summarizer) { dependencies.startGroup(constants_1.MESSAGES.STEP_LABELS.UPLOADING_ARTIFACT); userOutputFiles.map(f => assertFileExists(dependencies, f)); assertFileExists(dependencies, jsonOutputFile); - await dependencies.uploadArtifact(inputs.resultsArtifactName, userOutputFiles.length > 0 ? userOutputFiles : [jsonOutputFile]); + try { + await dependencies.uploadArtifact(inputs.resultsArtifactName, userOutputFiles.length > 0 ? userOutputFiles : [jsonOutputFile]); + } + catch (error) { + if (error instanceof Error && error.message.includes('not currently supported on GHES')) { + dependencies.warn(constants_1.MESSAGES.ARTIFACT_UPLOAD_SKIPPED_GHES); + } + else { + throw error; + } + } dependencies.endGroup(); dependencies.startGroup(constants_1.MESSAGES.STEP_LABELS.ANALYZING_RESULTS); assertFileExists(dependencies, jsonOutputFile); diff --git a/src/constants.ts b/src/constants.ts index 7ea18d6..433de61 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -33,7 +33,10 @@ export const MESSAGES = { UNEXPECTED_ERROR: `An unexpected error was thrown (see below). First check to make sure you're providing valid ` + `inputs. If you can't resolve the error, then create an issue at ` + - `https://github.com/forcedotcom/run-code-analyzer/issues.` + `https://github.com/forcedotcom/run-code-analyzer/issues.`, + ARTIFACT_UPLOAD_SKIPPED_GHES: + `Artifact upload is not supported on GitHub Enterprise Server. Skipping artifact upload. ` + + `All other results (violation counts, job summary, and pull request review) are still available.` } export const MESSAGE_FCNS = { PLUGIN_FOUND: (pluginName: string, pluginVersion: string) => diff --git a/src/main.ts b/src/main.ts index b3a4a58..b293272 100644 --- a/src/main.ts +++ b/src/main.ts @@ -52,10 +52,18 @@ export async function run( dependencies.startGroup(MESSAGES.STEP_LABELS.UPLOADING_ARTIFACT) userOutputFiles.map(f => assertFileExists(dependencies, f)) assertFileExists(dependencies, jsonOutputFile) - await dependencies.uploadArtifact( - inputs.resultsArtifactName, - userOutputFiles.length > 0 ? userOutputFiles : [jsonOutputFile] - ) + try { + await dependencies.uploadArtifact( + inputs.resultsArtifactName, + userOutputFiles.length > 0 ? userOutputFiles : [jsonOutputFile] + ) + } catch (error) { + if (error instanceof Error && error.message.includes('not currently supported on GHES')) { + dependencies.warn(MESSAGES.ARTIFACT_UPLOAD_SKIPPED_GHES) + } else { + throw error + } + } dependencies.endGroup() dependencies.startGroup(MESSAGES.STEP_LABELS.ANALYZING_RESULTS)