@@ -2,6 +2,7 @@ import test, { ExecutionContext } from "ava";
22import * as sinon from "sinon" ;
33
44import * as actionsUtil from "./actions-util" ;
5+ import { AnalysisKind } from "./analyses" ;
56import * as codeql from "./codeql" ;
67import * as configUtils from "./config-utils" ;
78import { Feature } from "./feature-flags" ;
@@ -28,12 +29,13 @@ test("post: init action with debug mode off", async (t) => {
2829 const gitHubVersion : util . GitHubVersion = {
2930 type : util . GitHubVariant . DOTCOM ,
3031 } ;
31- sinon . stub ( configUtils , "getConfig" ) . resolves ( {
32- debugMode : false ,
33- gitHubVersion,
34- languages : [ ] ,
35- packs : [ ] ,
36- } as unknown as configUtils . Config ) ;
32+ sinon . stub ( configUtils , "getConfig" ) . resolves (
33+ createTestConfig ( {
34+ debugMode : false ,
35+ gitHubVersion,
36+ languages : [ ] ,
37+ } ) ,
38+ ) ;
3739
3840 const uploadAllAvailableDebugArtifactsSpy = sinon . spy ( ) ;
3941 const printDebugLogsSpy = sinon . spy ( ) ;
@@ -295,6 +297,17 @@ test("uploading failed SARIF run fails when workflow does not reference github/c
295297 t . truthy ( result . upload_failed_run_stack_trace ) ;
296298} ) ;
297299
300+ test ( "not uploading failed SARIF when `code-scanning` is not an enabled 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 Scanning is not enabled." ,
308+ ) ;
309+ } ) ;
310+
298311function createTestWorkflow (
299312 steps : workflow . WorkflowJobStep [ ] ,
300313) : workflow . Workflow {
@@ -327,20 +340,22 @@ async function testFailedSarifUpload(
327340 expectUpload = true ,
328341 exportDiagnosticsEnabled = false ,
329342 matrix = { } ,
343+ analysisKinds = [ AnalysisKind . CodeScanning ] ,
330344 } : {
331345 category ?: string ;
332346 databaseExists ?: boolean ;
333347 expectUpload ?: boolean ;
334348 exportDiagnosticsEnabled ?: boolean ;
335349 matrix ?: { [ key : string ] : string } ;
350+ analysisKinds ?: AnalysisKind [ ] ;
336351 } = { } ,
337352) : Promise < initActionPostHelper . UploadFailedSarifResult > {
338- const config = {
353+ const config = createTestConfig ( {
354+ analysisKinds,
339355 codeQLCmd : "codeql" ,
340356 debugMode : true ,
341357 languages : [ ] ,
342- packs : [ ] ,
343- } as unknown as configUtils . Config ;
358+ } ) ;
344359 if ( databaseExists ) {
345360 config . dbLocation = "path/to/database" ;
346361 }
0 commit comments