Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions __tests__/fakes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ export class FakeDependencies implements Dependencies {
}

uploadArtifactCallHistory: { artifactName: string; artifactFiles: string[] }[] = []
uploadArtifactCallback: (() => Promise<void>) | undefined = undefined
async uploadArtifact(artifactName: string, artifactFiles: string[]): Promise<void> {
this.uploadArtifactCallHistory.push({ artifactName, artifactFiles })
if (this.uploadArtifactCallback) {
return this.uploadArtifactCallback()
}
return Promise.resolve()
}

Expand Down
34 changes: 34 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 14 additions & 2 deletions dist/index.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to push dist folder ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code build failed if i was not pushing it, seems for github action the index file should be up to date as they dont run npm install while running the action

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check this PR as well : https://github.com/forcedotcom/run-code-analyzer/pull/77/changes

here it has pushed index.js file

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
16 changes: 12 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading