Skip to content

Commit f902411

Browse files
committed
Add support for named collections of workflows
1 parent e65abf2 commit f902411

9 files changed

+115
-0
lines changed

.github/workflows/__go.yml

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

pr-checks/checks/go-custom-queries.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "Go: Custom queries"
22
description: "Checks that Go works in conjunction with a config file specifying custom queries"
3+
collection: go
34
operatingSystems:
45
- ubuntu
56
versions:

pr-checks/checks/go-indirect-tracing-workaround-diagnostic.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "Go: diagnostic when Go is changed after init step"
22
description: "Checks that we emit a diagnostic if Go is changed after the init step"
3+
collection: go
34
# only Linux is affected
45
operatingSystems: ["ubuntu"]
56
# pinned to a version which does not support statically linked binaries for indirect tracing

pr-checks/checks/go-indirect-tracing-workaround-no-file-program.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "Go: diagnostic when `file` is not installed"
22
description: "Checks that we emit a diagnostic if the `file` program is not installed"
3+
collection: go
34
# only Linux is affected
45
operatingSystems: ["ubuntu"]
56
# pinned to a version which does not support statically linked binaries for indirect tracing

pr-checks/checks/go-indirect-tracing-workaround.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "Go: workaround for indirect tracing"
22
description: "Checks that our workaround for indirect tracing for Go 1.21+ on Linux works"
3+
collection: go
34
# only Linux is affected
45
operatingSystems: ["ubuntu"]
56
# pinned to a version which does not support statically linked binaries for indirect tracing

pr-checks/checks/go-tracing-autobuilder.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "Go: tracing with autobuilder step"
22
description: "Checks that Go tracing works when using an autobuilder step"
3+
collection: go
34
operatingSystems: ["ubuntu", "macos"]
45
env:
56
DOTNET_GENERATE_ASPNET_CERTIFICATE: "false"

pr-checks/checks/go-tracing-custom-build-steps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "Go: tracing with custom build steps"
22
description: "Checks that Go tracing traces the build when using custom build steps"
3+
collection: go
34
operatingSystems: ["ubuntu", "macos"]
45
installGo: "true"
56
steps:

pr-checks/checks/go-tracing-legacy-workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: "Go: tracing with legacy workflow"
22
description: "Checks that we run the autobuilder in legacy workflows with neither an autobuild step nor manual build steps"
3+
collection: go
34
operatingSystems: ["ubuntu", "macos"]
45
env:
56
DOTNET_GENERATE_ASPNET_CERTIFICATE: "false"

pr-checks/sync.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def writeHeader(checkStream):
6060
this_dir = pathlib.Path(__file__).resolve().parent
6161

6262
allJobs = {}
63+
collections = {}
6364
for 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

Comments
 (0)