@@ -86,48 +86,45 @@ test("post: init action with debug mode on", async (t) => {
8686} ) ;
8787
8888test ( "uploads failed SARIF run for typical workflow" , async ( t ) => {
89- const actionsWorkflow : workflow . Workflow = {
90- name : "CodeQL" ,
91- on : {
92- push : {
93- branches : [ "main" ] ,
94- } ,
95- pull_request : {
96- branches : [ "main" ] ,
89+ const actionsWorkflow = createTestWorkflow ( [
90+ {
91+ name : "Checkout repository" ,
92+ uses : "actions/checkout@v3" ,
93+ } ,
94+ {
95+ name : "Initialize CodeQL" ,
96+ uses : "github/codeql-action/init@v2" ,
97+ with : {
98+ languages : "javascript" ,
9799 } ,
98100 } ,
99- jobs : {
100- analyze : {
101- name : "CodeQL Analysis" ,
102- "runs-on" : "ubuntu-latest" ,
103- steps : [
104- {
105- name : "Checkout repository" ,
106- uses : "actions/checkout@v3" ,
107- } ,
108- {
109- name : "Initialize CodeQL" ,
110- uses : "github/codeql-action/init@v2" ,
111- with : {
112- languages : "javascript" ,
113- } ,
114- } ,
115- {
116- name : "Perform CodeQL Analysis" ,
117- uses : "github/codeql-action/analyze@v2" ,
118- with : {
119- category : "my-category" ,
120- } ,
121- } ,
122- ] ,
101+ {
102+ name : "Perform CodeQL Analysis" ,
103+ uses : "github/codeql-action/analyze@v2" ,
104+ with : {
105+ category : "my-category" ,
123106 } ,
124107 } ,
125- } ;
108+ ] ) ;
126109 await testFailedSarifUpload ( t , actionsWorkflow , { category : "my-category" } ) ;
127110} ) ;
128111
129112test ( "uploading failed SARIF run fails when workflow does not reference github/codeql-action" , async ( t ) => {
130- const actionsWorkflow : workflow . Workflow = {
113+ const actionsWorkflow = createTestWorkflow ( [
114+ {
115+ name : "Checkout repository" ,
116+ uses : "actions/checkout@v3" ,
117+ } ,
118+ ] ) ;
119+ await t . throwsAsync (
120+ async ( ) => await testFailedSarifUpload ( t , actionsWorkflow )
121+ ) ;
122+ } ) ;
123+
124+ function createTestWorkflow (
125+ steps : workflow . WorkflowJobStep [ ]
126+ ) : workflow . Workflow {
127+ return {
131128 name : "CodeQL" ,
132129 on : {
133130 push : {
@@ -141,19 +138,11 @@ test("uploading failed SARIF run fails when workflow does not reference github/c
141138 analyze : {
142139 name : "CodeQL Analysis" ,
143140 "runs-on" : "ubuntu-latest" ,
144- steps : [
145- {
146- name : "Checkout repository" ,
147- uses : "actions/checkout@v3" ,
148- } ,
149- ] ,
141+ steps,
150142 } ,
151143 } ,
152144 } ;
153- await t . throwsAsync (
154- async ( ) => await testFailedSarifUpload ( t , actionsWorkflow )
155- ) ;
156- } ) ;
145+ }
157146
158147async function testFailedSarifUpload (
159148 t : ExecutionContext < unknown > ,
0 commit comments