Skip to content

Commit 5dac517

Browse files
feat: customize runners
1 parent a8dacaf commit 5dac517

2 files changed

Lines changed: 154 additions & 46 deletions

File tree

.github/workflows/__call-codeql.yml

Lines changed: 126 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ on:
1010
- master
1111
pull_request:
1212
workflow_call:
13+
inputs:
14+
runner:
15+
required: false
16+
type: string
17+
default: "[ubuntu-latest]"
1318

1419
jobs:
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:
@@ -64,6 +71,18 @@ jobs:
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) }}

.github/workflows/__call-common-lint.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ permissions: {}
88
on:
99
pull_request:
1010
workflow_call:
11+
inputs:
12+
actionlint_config:
13+
required: false
14+
type: string
15+
runner:
16+
required: false
17+
type: string
18+
default: "[ubuntu-latest]"
1119

1220
jobs:
1321
lint:
1422
name: Common Lint
1523
permissions:
1624
contents: read
17-
runs-on: ubuntu-latest
25+
runs-on: ${{ (inputs && inputs.runner && fromJson(inputs.runner)) || 'ubuntu-latest' }}
1826
env:
1927
CLANG_FORMAT_VERSION: 20
2028
steps:
@@ -64,8 +72,8 @@ jobs:
6472
6573
for name in "${!files[@]}"; do
6674
if [ ! -f "${name}.json" ]; then
67-
echo "Downloading ${name}.json"
6875
url="${files[$name]}"
76+
echo "Downloading ${name}.json from ${url}"
6977
curl \
7078
-fsSL \
7179
--retry 3 \
@@ -101,15 +109,22 @@ jobs:
101109
- name: Install actionlint
102110
id: get_actionlint
103111
shell: bash
112+
env:
113+
ACTIONLINT_CONFIG: ${{ inputs.actionlint_config }}
104114
run: |
105115
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
106116
107-
if [ ! -f ".github/actionlint.yml" ]; then
117+
if [ -n "${ACTIONLINT_CONFIG}" ]; then
118+
mkdir -p .github
119+
printf "%s" "${ACTIONLINT_CONFIG}" > .github/actionlint.yml
120+
elif [ ! -f ".github/actionlint.yml" ]; then
121+
url="https://raw.githubusercontent.com/LizardByte/.github/master/.github/actionlint.yml"
122+
echo "Downloading ${url} with curl"
108123
curl \
109124
-fsS \
110125
--retry 3 \
111126
-o ".github/actionlint.yml" \
112-
"https://raw.githubusercontent.com/LizardByte/.github/master/.github/actionlint.yml"
127+
${url}
113128
fi
114129
115130
- name: Replace shell
@@ -349,6 +364,15 @@ jobs:
349364
shell: pwsh
350365
run: |
351366
# PSScriptAnalyzer is already installed on GitHub runners
367+
if ($env:RUNNER_NAME -notlike 'GitHub Actions*') {
368+
$repo = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue
369+
if (-not $repo) {
370+
Register-PSRepository -Default -InstallationPolicy Trusted
371+
} else {
372+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
373+
}
374+
Install-Module -Name PSScriptAnalyzer -Force
375+
}
352376
353377
# To see a list of available rules, run the following command:
354378
# Get-ScriptAnalyzerRule | Format-List

0 commit comments

Comments
 (0)