Skip to content

Commit 61f2979

Browse files
feat: customize runners (#529)
1 parent ec8dc4d commit 61f2979

2 files changed

Lines changed: 108 additions & 62 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: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,32 @@ permissions: {}
88
on:
99
pull_request:
1010
workflow_call:
11+
inputs:
12+
actionlint_config:
13+
required: false
14+
type: string
15+
check_trailing_space_ignore_pattern:
16+
required: false
17+
type: string
18+
default: ""
19+
runner:
20+
required: false
21+
type: string
22+
default: "[ubuntu-latest]"
1123

1224
jobs:
1325
lint:
1426
name: Common Lint
1527
permissions:
1628
contents: read
17-
runs-on: ubuntu-latest
29+
pull-requests: read
30+
runs-on: ${{ (inputs && inputs.runner && fromJson(inputs.runner)) || 'ubuntu-latest' }}
1831
env:
1932
CLANG_FORMAT_VERSION: 20
2033
steps:
2134
- name: Checkout
2235
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2336

24-
- name: Get changed files
25-
id: changed_files
26-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
27-
with:
28-
script: |
29-
const opts = github.rest.pulls.listFiles.endpoint.merge({
30-
owner: context.repo.owner,
31-
repo: context.repo.repo,
32-
pull_number: context.issue.number,
33-
});
34-
const changedFiles = await github.paginate(opts);
35-
const changedFilesString = changedFiles.map(file => file.filename).join(' ');
36-
console.log(`Changed files: ${changedFilesString}`);
37-
core.setOutput('CHANGED_FILES', changedFilesString);
38-
3937
- name: Download problem matchers
4038
shell: bash
4139
working-directory: .github
@@ -64,8 +62,8 @@ jobs:
6462
6563
for name in "${!files[@]}"; do
6664
if [ ! -f "${name}.json" ]; then
67-
echo "Downloading ${name}.json"
6865
url="${files[$name]}"
66+
echo "Downloading ${name}.json from ${url}"
6967
curl \
7068
-fsSL \
7169
--retry 3 \
@@ -101,15 +99,22 @@ jobs:
10199
- name: Install actionlint
102100
id: get_actionlint
103101
shell: bash
102+
env:
103+
ACTIONLINT_CONFIG: ${{ inputs.actionlint_config }}
104104
run: |
105105
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
106106
107-
if [ ! -f ".github/actionlint.yml" ]; then
107+
if [ -n "${ACTIONLINT_CONFIG}" ]; then
108+
mkdir -p .github
109+
printf "%s" "${ACTIONLINT_CONFIG}" > .github/actionlint.yml
110+
elif [ ! -f ".github/actionlint.yml" ]; then
111+
url="https://raw.githubusercontent.com/LizardByte/.github/master/.github/actionlint.yml"
112+
echo "Downloading ${url} with curl"
108113
curl \
109114
-fsS \
110115
--retry 3 \
111116
-o ".github/actionlint.yml" \
112-
"https://raw.githubusercontent.com/LizardByte/.github/master/.github/actionlint.yml"
117+
${url}
113118
fi
114119
115120
- name: Replace shell
@@ -139,39 +144,11 @@ jobs:
139144
echo "::remove-matcher owner=actionlint::"
140145
exit ${error}
141146
142-
- name: check-eol
143-
if: always()
144-
shell: bash
145-
run: |
146-
error=0
147-
for file in ${{ steps.changed_files.outputs.CHANGED_FILES }}; do
148-
149-
# Skip empty files
150-
if [[ ! -s "$file" ]]; then
151-
continue
152-
fi
153-
154-
# Skip binary files using file --mime-encoding
155-
if file --mime-encoding "$file" | grep -q ": binary$"; then
156-
continue
157-
fi
158-
159-
# Check if file ends with newline using tail -c 1
160-
if [[ -n "$(tail -c 1 "$file")" ]]; then
161-
error=1
162-
title="EOL linting error"
163-
message="File '$file' does not end with a newline character."
164-
line=$(($(wc -l < "$file") + 1))
165-
166-
echo "::error file=$file,line=$line,title=$title::$message"
167-
fi
168-
done
169-
170-
exit ${error}
171-
172147
- name: check-trailing-spaces
173148
if: always()
174-
uses: marcopaganini/check-trailing-spaces@8cb92e10874ed9bd54d89f2848f98308242527bd # v2.0.0
149+
uses: LizardByte/actions/actions/trailing_spaces@70bb8d394d1c92f6113aeec6ae9cc959a5763d15 # v2026.227.200013
150+
with:
151+
ignore_patterns: ${{ inputs.check_trailing_space_ignore_pattern }}
175152

176153
- name: C++ - find files
177154
id: cpp_files
@@ -349,6 +326,15 @@ jobs:
349326
shell: pwsh
350327
run: |
351328
# PSScriptAnalyzer is already installed on GitHub runners
329+
if ($env:RUNNER_NAME -notlike 'GitHub Actions*') {
330+
$repo = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue
331+
if (-not $repo) {
332+
Register-PSRepository -Default -InstallationPolicy Trusted
333+
} else {
334+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
335+
}
336+
Install-Module -Name PSScriptAnalyzer -Force
337+
}
352338
353339
# To see a list of available rules, run the following command:
354340
# Get-ScriptAnalyzerRule | Format-List

0 commit comments

Comments
 (0)