@@ -60,6 +60,7 @@ def writeHeader(checkStream):
6060this_dir = pathlib .Path (__file__ ).resolve ().parent
6161
6262allJobs = {}
63+ collections = {}
6364for file in (this_dir / 'checks' ).glob ('*.yml' ):
6465 with open (file , 'r' ) as checkStream :
6566 checkSpecification = yaml .load (checkStream )
@@ -160,6 +161,14 @@ def writeHeader(checkStream):
160161 checkJob ['env' ]['CODEQL_ACTION_TEST_MODE' ] = True
161162 checkName = file .stem
162163
164+ # If this check belongs to a named collection, record it.
165+ if 'collection' in checkSpecification :
166+ collection_name = checkSpecification ['collection' ]
167+ collections .setdefault (collection_name , []).append ({
168+ 'specification' : checkSpecification ,
169+ 'checkName' : checkName
170+ })
171+
163172 raw_file = this_dir .parent / ".github" / "workflows" / f"__{ checkName } .yml.raw"
164173 with open (raw_file , 'w' ) as output_stream :
165174 writeHeader (output_stream )
@@ -190,3 +199,45 @@ def writeHeader(checkStream):
190199 content = input_stream .read ()
191200 output_stream .write ("\n " .join (list (map (lambda x :x .rstrip (), content .splitlines ()))+ ['' ]))
192201 os .remove (raw_file )
202+
203+ # write workflow files for collections
204+ for collection_name in collections :
205+ jobs = {}
206+
207+ for check in collections [collection_name ]:
208+ checkName = check ['checkName' ]
209+ checkSpecification = check ['specification' ]
210+ jobs [checkName ] = {
211+ 'name' : checkSpecification ['name' ],
212+ 'permissions' : {
213+ 'contents' : 'read' ,
214+ 'security-events' : 'read'
215+ },
216+ 'uses' : "./.github/workflows/" + f"__{ checkName } .yml" ,
217+ }
218+
219+ raw_file = this_dir .parent / ".github" / "workflows" / f"__{ collection_name } .yml.raw"
220+ with open (raw_file , 'w' ) as output_stream :
221+ writeHeader (output_stream )
222+ yaml .dump ({
223+ 'name' : f"Manual Check - { collection_name } " ,
224+ 'env' : {
225+ 'GITHUB_TOKEN' : '${{ secrets.GITHUB_TOKEN }}' ,
226+ 'GO111MODULE' : 'auto'
227+ },
228+ 'on' : {
229+ 'push' : {
230+ 'paths' : [
231+ f'.github/workflows/__{ collection_name } .yml'
232+ ]
233+ },
234+ 'workflow_dispatch' : {},
235+ },
236+ 'jobs' : jobs
237+ }, output_stream )
238+
239+ with open (raw_file , 'r' ) as input_stream :
240+ with open (this_dir .parent / ".github" / "workflows" / f"__{ collection_name } .yml" , 'w' ) as output_stream :
241+ content = input_stream .read ()
242+ output_stream .write ("\n " .join (list (map (lambda x :x .rstrip (), content .splitlines ()))+ ['' ]))
243+ os .remove (raw_file )
0 commit comments