1010 - master
1111 pull_request :
1212 workflow_call :
13+ inputs :
14+ runner :
15+ required : false
16+ type : string
17+ default : " [ubuntu-latest]"
1318
1419jobs :
1520 languages :
@@ -19,14 +24,16 @@ jobs:
1924 outputs :
2025 matrix : ${{ steps.lang.outputs.result }}
2126 continue : ${{ steps.continue.outputs.result }}
22- runs-on : ubuntu-latest
27+ runs-on : ${{ (inputs && inputs.runner && fromJson(inputs.runner)) || ' ubuntu-latest' }}
2328 steps :
2429 - name : Checkout repository
2530 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2631
2732 - name : Get repo languages
2833 id : lang
2934 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
35+ env :
36+ RUNNER_INPUT : ${{ inputs.runner }}
3037 with :
3138 script : |
3239 // CodeQL supports the following:
6471 'typescript': 'javascript',
6572 }
6673
74+ // Get custom runner input if provided
75+ const runnerInput = process.env.RUNNER_INPUT || '["ubuntu-latest"]'
76+ let customRunners = []
77+ try {
78+ customRunners = JSON.parse(runnerInput)
79+ console.log(`Custom runners provided: ${JSON.stringify(customRunners)}`)
80+ } catch (e) {
81+ console.log(`Failed to parse runner input, using default behavior: ${e}`)
82+ }
83+
84+ const useCustomRunners = customRunners.length > 0 && runnerInput !== '["ubuntu-latest"]'
85+
6786 const repo = context.repo
6887 const response = await github.rest.repos.listLanguages(repo)
6988 let matrix = {
@@ -81,13 +100,31 @@ jobs:
81100 // Add actions language if workflow files exist
82101 if (hasYmlFiles) {
83102 console.log('Found GitHub Actions workflow files. Adding actions to the matrix.');
84- matrix['include'].push({
85- "category": "/language:actions",
86- "language": "actions",
87- "name": "actions",
88- "os": "ubuntu-latest",
89- "build-mode": "none",
90- });
103+
104+ if (useCustomRunners) {
105+ // Use custom runners for actions language
106+ for (let runner of customRunners) {
107+ const runnerName = customRunners.length === 1 ? '' : `, ${runner}`
108+ matrix['include'].push({
109+ "category": "/language:actions",
110+ "language": "actions",
111+ "name": `actions${runnerName}`,
112+ "os": "ubuntu-latest",
113+ "runner": runner,
114+ "build-mode": "none",
115+ });
116+ }
117+ } else {
118+ // Use default behavior
119+ matrix['include'].push({
120+ "category": "/language:actions",
121+ "language": "actions",
122+ "name": "actions",
123+ "os": "ubuntu-latest",
124+ "runner": "ubuntu-latest",
125+ "build-mode": "none",
126+ });
127+ }
91128 }
92129
93130 for (let [key, value] of Object.entries(response.data)) {
@@ -104,41 +141,88 @@ jobs:
104141 addedLanguages.add(normalizedKey)
105142
106143 console.log(`Found supported language: ${normalizedKey}`)
107- let osList = ['ubuntu-latest'];
108- if (normalizedKey === 'swift') {
109- osList = ['macos-latest'];
110- }
111- for (let os of osList) {
112- // set name for matrix
113- let name = osList.length === 1 ? normalizedKey : `${normalizedKey}, ${os}`
114-
115- // set category for matrix
116- let category = `/language:${normalizedKey}`
117- let build_mode = 'none';
118-
119- // Set build mode based on language
120- switch (normalizedKey) {
121- case 'csharp':
122- build_mode = 'autobuild'
123- break
124- case 'go':
125- build_mode = 'autobuild'
126- break
127- case 'java':
128- build_mode = 'autobuild'
129- break
130- default:
131- build_mode = 'none'
144+
145+ if (useCustomRunners) {
146+ // Use custom runners
147+ for (let runner of customRunners) {
148+ // set name for matrix
149+ const runnerName = customRunners.length === 1 ? '' : `, ${runner}`
150+ let name = `${normalizedKey}${runnerName}`
151+
152+ // set category for matrix
153+ let category = `/language:${normalizedKey}`
154+ let build_mode = 'none';
155+
156+ // Set build mode based on language
157+ switch (normalizedKey) {
158+ case 'csharp':
159+ build_mode = 'autobuild'
160+ break
161+ case 'go':
162+ build_mode = 'autobuild'
163+ break
164+ case 'java':
165+ build_mode = 'autobuild'
166+ break
167+ default:
168+ build_mode = 'none'
169+ }
170+
171+ // Determine OS based on language (for display purposes)
172+ let os = 'ubuntu-latest'
173+ if (normalizedKey === 'swift') {
174+ os = 'macos-latest'
175+ }
176+
177+ // add to matrix
178+ matrix['include'].push({
179+ "category": category,
180+ "language": normalizedKey,
181+ "name": name,
182+ "os": os,
183+ "runner": runner,
184+ "build-mode": build_mode,
185+ })
186+ }
187+ } else {
188+ // Use default OS-based behavior
189+ let osList = ['ubuntu-latest'];
190+ if (normalizedKey === 'swift') {
191+ osList = ['macos-latest'];
132192 }
193+ for (let os of osList) {
194+ // set name for matrix
195+ let name = osList.length === 1 ? normalizedKey : `${normalizedKey}, ${os}`
133196
134- // add to matrix
135- matrix['include'].push({
136- "category": category,
137- "language": normalizedKey,
138- "name": name,
139- "os": os,
140- "build-mode": build_mode,
141- })
197+ // set category for matrix
198+ let category = `/language:${normalizedKey}`
199+ let build_mode = 'none';
200+
201+ // Set build mode based on language
202+ switch (normalizedKey) {
203+ case 'csharp':
204+ build_mode = 'autobuild'
205+ break
206+ case 'go':
207+ build_mode = 'autobuild'
208+ break
209+ case 'java':
210+ build_mode = 'autobuild'
211+ break
212+ default:
213+ build_mode = 'none'
214+ }
215+
216+ // add to matrix
217+ matrix['include'].push({
218+ "category": category,
219+ "language": normalizedKey,
220+ "name": name,
221+ "os": os,
222+ "runner": os,
223+ "build-mode": build_mode,
224+ })
225+ }
142226 }
143227 }
144228 }
@@ -172,7 +256,7 @@ jobs:
172256 actions : read
173257 contents : read
174258 security-events : write
175- runs-on : ${{ matrix.os || 'ubuntu-latest' }}
259+ runs-on : ${{ matrix.runner || matrix. os || 'ubuntu-latest' }}
176260 strategy :
177261 fail-fast : false
178262 matrix : ${{ fromJson(needs.languages.outputs.matrix) }}
0 commit comments