@@ -11,6 +11,7 @@ import { parseRepositoryNwo } from "./repository";
1111import {
1212 createFeatures ,
1313 getRecordingLogger ,
14+ LoggedMessage ,
1415 setupTests ,
1516} from "./testing-utils" ;
1617import * as uploadLib from "./upload-lib" ;
@@ -111,6 +112,40 @@ test("uploads failed SARIF run for typical workflow", async (t) => {
111112 await testFailedSarifUpload ( t , actionsWorkflow , { category : "my-category" } ) ;
112113} ) ;
113114
115+ test ( "doesn't upload failed SARIF for workflow with upload: false" , async ( t ) => {
116+ const actionsWorkflow = createTestWorkflow ( [
117+ {
118+ name : "Checkout repository" ,
119+ uses : "actions/checkout@v3" ,
120+ } ,
121+ {
122+ name : "Initialize CodeQL" ,
123+ uses : "github/codeql-action/init@v2" ,
124+ with : {
125+ languages : "javascript" ,
126+ } ,
127+ } ,
128+ {
129+ name : "Perform CodeQL Analysis" ,
130+ uses : "github/codeql-action/analyze@v2" ,
131+ with : {
132+ category : "my-category" ,
133+ upload : false ,
134+ } ,
135+ } ,
136+ ] ) ;
137+ await testFailedSarifUpload ( t , actionsWorkflow , {
138+ expectedLogs : [
139+ {
140+ message :
141+ "Won't upload a failed SARIF file since SARIF upload is disabled." ,
142+ type : "debug" ,
143+ } ,
144+ ] ,
145+ expectUpload : false ,
146+ } ) ;
147+ } ) ;
148+
114149test ( "uploading failed SARIF run fails when workflow does not reference github/codeql-action" , async ( t ) => {
115150 const actionsWorkflow = createTestWorkflow ( [
116151 {
@@ -149,7 +184,15 @@ function createTestWorkflow(
149184async function testFailedSarifUpload (
150185 t : ExecutionContext < unknown > ,
151186 actionsWorkflow : workflow . Workflow ,
152- { category } : { category ?: string } = { }
187+ {
188+ category,
189+ expectedLogs = [ ] ,
190+ expectUpload = true ,
191+ } : {
192+ category ?: string ;
193+ expectedLogs ?: LoggedMessage [ ] ;
194+ expectUpload ?: boolean ;
195+ } = { }
153196) : Promise < void > {
154197 const config = {
155198 codeQLCmd : "codeql" ,
@@ -180,23 +223,29 @@ async function testFailedSarifUpload(
180223 createFeatures ( [ Feature . UploadFailedSarifEnabled ] ) ,
181224 getRecordingLogger ( messages )
182225 ) ;
183- t . deepEqual ( messages , [ ] ) ;
184- t . true (
185- diagnosticsExportStub . calledOnceWith ( sinon . match . string , category ) ,
186- `Actual args were: ${ diagnosticsExportStub . args } `
187- ) ;
188- t . true (
189- uploadFromActions . calledOnceWith (
190- sinon . match . string ,
191- sinon . match . string ,
192- category ,
193- sinon . match . any
194- ) ,
195- `Actual args were: ${ uploadFromActions . args } `
196- ) ;
197- t . true (
198- waitForProcessing . calledOnceWith ( sinon . match . any , "42" , sinon . match . any , {
199- isUnsuccessfulExecution : true ,
200- } )
201- ) ;
226+ t . deepEqual ( messages , expectedLogs ) ;
227+ if ( expectUpload ) {
228+ t . true (
229+ diagnosticsExportStub . calledOnceWith ( sinon . match . string , category ) ,
230+ `Actual args were: ${ diagnosticsExportStub . args } `
231+ ) ;
232+ t . true (
233+ uploadFromActions . calledOnceWith (
234+ sinon . match . string ,
235+ sinon . match . string ,
236+ category ,
237+ sinon . match . any
238+ ) ,
239+ `Actual args were: ${ uploadFromActions . args } `
240+ ) ;
241+ t . true (
242+ waitForProcessing . calledOnceWith ( sinon . match . any , "42" , sinon . match . any , {
243+ isUnsuccessfulExecution : true ,
244+ } )
245+ ) ;
246+ } else {
247+ t . true ( diagnosticsExportStub . notCalled ) ;
248+ t . true ( uploadFromActions . notCalled ) ;
249+ t . true ( waitForProcessing . notCalled ) ;
250+ }
202251}
0 commit comments