diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 42985a5d8..c1fb450be 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -129786,6 +129786,9 @@ function appendExtraQueryExclusions(extraQueryExclusions, cliConfig) { } return augmentedConfig; } +function isCodeQualityEnabled(config) { + return config.analysisKinds.includes("code-quality" /* CodeQuality */); +} // src/setup-codeql.ts var fs12 = __toESM(require("fs")); @@ -133750,6 +133753,11 @@ async function tryUploadSarifIfRunFailed(config, repositoryNwo, features, logger "CODEQL_ACTION_JOB_STATUS" /* JOB_STATUS */, process.env["CODEQL_ACTION_JOB_STATUS" /* JOB_STATUS */] ?? "JOB_STATUS_CONFIGURATION_ERROR" /* ConfigErrorStatus */ ); + if (config.analysisKinds.length === 1 && isCodeQualityEnabled(config)) { + return { + upload_failed_run_skipped_because: "Code Quality is the only enabled analysis kind." + }; + } try { return await maybeUploadFailedSarif( config, diff --git a/src/init-action-post-helper.test.ts b/src/init-action-post-helper.test.ts index bd911a8a9..e6f4243ea 100644 --- a/src/init-action-post-helper.test.ts +++ b/src/init-action-post-helper.test.ts @@ -2,6 +2,7 @@ import test, { ExecutionContext } from "ava"; import * as sinon from "sinon"; import * as actionsUtil from "./actions-util"; +import { AnalysisKind } from "./analyses"; import * as codeql from "./codeql"; import * as configUtils from "./config-utils"; import { Feature } from "./feature-flags"; @@ -296,6 +297,17 @@ test("uploading failed SARIF run fails when workflow does not reference github/c t.truthy(result.upload_failed_run_stack_trace); }); +test("not uploading failed SARIF when `code-quality` is the only analysis kind", async (t) => { + const result = await testFailedSarifUpload(t, createTestWorkflow([]), { + analysisKinds: [AnalysisKind.CodeQuality], + expectUpload: false, + }); + t.is( + result.upload_failed_run_skipped_because, + "Code Quality is the only enabled analysis kind.", + ); +}); + function createTestWorkflow( steps: workflow.WorkflowJobStep[], ): workflow.Workflow { @@ -328,15 +340,18 @@ async function testFailedSarifUpload( expectUpload = true, exportDiagnosticsEnabled = false, matrix = {}, + analysisKinds = [AnalysisKind.CodeScanning], }: { category?: string; databaseExists?: boolean; expectUpload?: boolean; exportDiagnosticsEnabled?: boolean; matrix?: { [key: string]: string }; + analysisKinds?: AnalysisKind[]; } = {}, ): Promise { const config = createTestConfig({ + analysisKinds, codeQLCmd: "codeql", debugMode: true, languages: [], diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index 7d46095e9..331a8c10b 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -7,7 +7,7 @@ import * as actionsUtil from "./actions-util"; import { CodeScanning } from "./analyses"; import { getApiClient } from "./api-client"; import { CodeQL, getCodeQL } from "./codeql"; -import { Config } from "./config-utils"; +import { Config, isCodeQualityEnabled } from "./config-utils"; import * as dependencyCaching from "./dependency-caching"; import { EnvVar } from "./environment"; import { Feature, FeatureEnablement } from "./feature-flags"; @@ -139,6 +139,16 @@ export async function tryUploadSarifIfRunFailed( EnvVar.JOB_STATUS, process.env[EnvVar.JOB_STATUS] ?? JobStatus.ConfigErrorStatus, ); + + // If the only enabled analysis kind is `code-quality`, then we shouldn't + // upload the failed SARIF to Code Scanning. + if (config.analysisKinds.length === 1 && isCodeQualityEnabled(config)) { + return { + upload_failed_run_skipped_because: + "Code Quality is the only enabled analysis kind.", + }; + } + try { return await maybeUploadFailedSarif( config,