Skip to content

Commit 1eda941

Browse files
feat: customize runners
1 parent a8dacaf commit 1eda941

2 files changed

Lines changed: 101 additions & 16 deletions

File tree

.github/workflows/__call-codeql.yml

Lines changed: 72 additions & 12 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 = {
@@ -86,6 +105,7 @@ jobs:
86105
"language": "actions",
87106
"name": "actions",
88107
"os": "ubuntu-latest",
108+
"runner": useCustomRunners ? customRunners : "ubuntu-latest",
89109
"build-mode": "none",
90110
});
91111
}
@@ -104,15 +124,9 @@ jobs:
104124
addedLanguages.add(normalizedKey)
105125
106126
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}`
114127
115-
// set category for matrix
128+
if (useCustomRunners) {
129+
// Use custom runners as a group/pool
116130
let category = `/language:${normalizedKey}`
117131
let build_mode = 'none';
118132
@@ -131,14 +145,60 @@ jobs:
131145
build_mode = 'none'
132146
}
133147
134-
// add to matrix
148+
// Determine OS based on language (for display purposes)
149+
let os = 'ubuntu-latest'
150+
if (normalizedKey === 'swift') {
151+
os = 'macos-latest'
152+
}
153+
154+
// add to matrix with runner group
135155
matrix['include'].push({
136156
"category": category,
137157
"language": normalizedKey,
138-
"name": name,
158+
"name": normalizedKey,
139159
"os": os,
160+
"runner": customRunners,
140161
"build-mode": build_mode,
141162
})
163+
} else {
164+
// Use default OS-based behavior
165+
let osList = ['ubuntu-latest'];
166+
if (normalizedKey === 'swift') {
167+
osList = ['macos-latest'];
168+
}
169+
for (let os of osList) {
170+
// set name for matrix
171+
let name = osList.length === 1 ? normalizedKey : `${normalizedKey}, ${os}`
172+
173+
// set category for matrix
174+
let category = `/language:${normalizedKey}`
175+
let build_mode = 'none';
176+
177+
// Set build mode based on language
178+
switch (normalizedKey) {
179+
case 'csharp':
180+
build_mode = 'autobuild'
181+
break
182+
case 'go':
183+
build_mode = 'autobuild'
184+
break
185+
case 'java':
186+
build_mode = 'autobuild'
187+
break
188+
default:
189+
build_mode = 'none'
190+
}
191+
192+
// add to matrix
193+
matrix['include'].push({
194+
"category": category,
195+
"language": normalizedKey,
196+
"name": name,
197+
"os": os,
198+
"runner": os,
199+
"build-mode": build_mode,
200+
})
201+
}
142202
}
143203
}
144204
}
@@ -172,7 +232,7 @@ jobs:
172232
actions: read
173233
contents: read
174234
security-events: write
175-
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
235+
runs-on: ${{ matrix.runner }}
176236
strategy:
177237
fail-fast: false
178238
matrix: ${{ fromJson(needs.languages.outputs.matrix) }}

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ 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+
pull-requests: read
26+
runs-on: ${{ (inputs && inputs.runner && fromJson(inputs.runner)) || 'ubuntu-latest' }}
1827
env:
1928
CLANG_FORMAT_VERSION: 20
2029
steps:
@@ -64,8 +73,8 @@ jobs:
6473
6574
for name in "${!files[@]}"; do
6675
if [ ! -f "${name}.json" ]; then
67-
echo "Downloading ${name}.json"
6876
url="${files[$name]}"
77+
echo "Downloading ${name}.json from ${url}"
6978
curl \
7079
-fsSL \
7180
--retry 3 \
@@ -101,15 +110,22 @@ jobs:
101110
- name: Install actionlint
102111
id: get_actionlint
103112
shell: bash
113+
env:
114+
ACTIONLINT_CONFIG: ${{ inputs.actionlint_config }}
104115
run: |
105116
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
106117
107-
if [ ! -f ".github/actionlint.yml" ]; then
118+
if [ -n "${ACTIONLINT_CONFIG}" ]; then
119+
mkdir -p .github
120+
printf "%s" "${ACTIONLINT_CONFIG}" > .github/actionlint.yml
121+
elif [ ! -f ".github/actionlint.yml" ]; then
122+
url="https://raw.githubusercontent.com/LizardByte/.github/master/.github/actionlint.yml"
123+
echo "Downloading ${url} with curl"
108124
curl \
109125
-fsS \
110126
--retry 3 \
111127
-o ".github/actionlint.yml" \
112-
"https://raw.githubusercontent.com/LizardByte/.github/master/.github/actionlint.yml"
128+
${url}
113129
fi
114130
115131
- name: Replace shell
@@ -349,6 +365,15 @@ jobs:
349365
shell: pwsh
350366
run: |
351367
# PSScriptAnalyzer is already installed on GitHub runners
368+
if ($env:RUNNER_NAME -notlike 'GitHub Actions*') {
369+
$repo = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue
370+
if (-not $repo) {
371+
Register-PSRepository -Default -InstallationPolicy Trusted
372+
} else {
373+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
374+
}
375+
Install-Module -Name PSScriptAnalyzer -Force
376+
}
352377
353378
# To see a list of available rules, run the following command:
354379
# Get-ScriptAnalyzerRule | Format-List

0 commit comments

Comments
 (0)