Skip to content

Commit c77b3fb

Browse files
committed
Skip failed SARIF upload if analysis-kinds: code-quality
1 parent 2a54ab5 commit c77b3fb

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

lib/init-action-post.js

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/init-action-post-helper.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import test, { ExecutionContext } from "ava";
22
import * as sinon from "sinon";
33

44
import * as actionsUtil from "./actions-util";
5+
import { AnalysisKind } from "./analyses";
56
import * as codeql from "./codeql";
67
import * as configUtils from "./config-utils";
78
import { Feature } from "./feature-flags";
@@ -296,6 +297,17 @@ test("uploading failed SARIF run fails when workflow does not reference github/c
296297
t.truthy(result.upload_failed_run_stack_trace);
297298
});
298299

300+
test("not uploading failed SARIF when `code-quality` is the only analysis kind", async (t) => {
301+
const result = await testFailedSarifUpload(t, createTestWorkflow([]), {
302+
analysisKinds: [AnalysisKind.CodeQuality],
303+
expectUpload: false,
304+
});
305+
t.is(
306+
result.upload_failed_run_skipped_because,
307+
"Code Quality is the only enabled analysis kind.",
308+
);
309+
});
310+
299311
function createTestWorkflow(
300312
steps: workflow.WorkflowJobStep[],
301313
): workflow.Workflow {
@@ -328,15 +340,18 @@ async function testFailedSarifUpload(
328340
expectUpload = true,
329341
exportDiagnosticsEnabled = false,
330342
matrix = {},
343+
analysisKinds = [AnalysisKind.CodeScanning],
331344
}: {
332345
category?: string;
333346
databaseExists?: boolean;
334347
expectUpload?: boolean;
335348
exportDiagnosticsEnabled?: boolean;
336349
matrix?: { [key: string]: string };
350+
analysisKinds?: AnalysisKind[];
337351
} = {},
338352
): Promise<initActionPostHelper.UploadFailedSarifResult> {
339353
const config = createTestConfig({
354+
analysisKinds,
340355
codeQLCmd: "codeql",
341356
debugMode: true,
342357
languages: [],

src/init-action-post-helper.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as actionsUtil from "./actions-util";
77
import { CodeScanning } from "./analyses";
88
import { getApiClient } from "./api-client";
99
import { CodeQL, getCodeQL } from "./codeql";
10-
import { Config } from "./config-utils";
10+
import { Config, isCodeQualityEnabled } from "./config-utils";
1111
import * as dependencyCaching from "./dependency-caching";
1212
import { EnvVar } from "./environment";
1313
import { Feature, FeatureEnablement } from "./feature-flags";
@@ -139,6 +139,16 @@ export async function tryUploadSarifIfRunFailed(
139139
EnvVar.JOB_STATUS,
140140
process.env[EnvVar.JOB_STATUS] ?? JobStatus.ConfigErrorStatus,
141141
);
142+
143+
// If the only enabled analysis kind is `code-quality`, then we shouldn't
144+
// upload the failed SARIF to Code Scanning.
145+
if (config.analysisKinds.length === 1 && isCodeQualityEnabled(config)) {
146+
return {
147+
upload_failed_run_skipped_because:
148+
"Code Quality is the only enabled analysis kind.",
149+
};
150+
}
151+
142152
try {
143153
return await maybeUploadFailedSarif(
144154
config,

0 commit comments

Comments
 (0)