Skip to content

Commit faeeb23

Browse files
feat: customize runners
1 parent 796b637 commit faeeb23

2 files changed

Lines changed: 103 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: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,28 @@ 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:
2130
- name: Checkout
2231
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2332

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-
3933
- name: Download problem matchers
4034
shell: bash
4135
working-directory: .github
@@ -64,8 +58,8 @@ jobs:
6458
6559
for name in "${!files[@]}"; do
6660
if [ ! -f "${name}.json" ]; then
67-
echo "Downloading ${name}.json"
6861
url="${files[$name]}"
62+
echo "Downloading ${name}.json from ${url}"
6963
curl \
7064
-fsSL \
7165
--retry 3 \
@@ -101,15 +95,22 @@ jobs:
10195
- name: Install actionlint
10296
id: get_actionlint
10397
shell: bash
98+
env:
99+
ACTIONLINT_CONFIG: ${{ inputs.actionlint_config }}
104100
run: |
105101
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
106102
107-
if [ ! -f ".github/actionlint.yml" ]; then
103+
if [ -n "${ACTIONLINT_CONFIG}" ]; then
104+
mkdir -p .github
105+
printf "%s" "${ACTIONLINT_CONFIG}" > .github/actionlint.yml
106+
elif [ ! -f ".github/actionlint.yml" ]; then
107+
url="https://raw.githubusercontent.com/LizardByte/.github/master/.github/actionlint.yml"
108+
echo "Downloading ${url} with curl"
108109
curl \
109110
-fsS \
110111
--retry 3 \
111112
-o ".github/actionlint.yml" \
112-
"https://raw.githubusercontent.com/LizardByte/.github/master/.github/actionlint.yml"
113+
${url}
113114
fi
114115
115116
- name: Replace shell
@@ -139,39 +140,10 @@ jobs:
139140
echo "::remove-matcher owner=actionlint::"
140141
exit ${error}
141142
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-
172143
- name: check-trailing-spaces
173144
if: always()
174-
uses: marcopaganini/check-trailing-spaces@8cb92e10874ed9bd54d89f2848f98308242527bd # v2.0.0
145+
uses:
146+
LizardByte/actions/actions/check_trailing_spaces@30be428f5c54b82056fe9d63e8c4da4b86130ebe # v2026.227.132933
175147

176148
- name: C++ - find files
177149
id: cpp_files
@@ -349,6 +321,15 @@ jobs:
349321
shell: pwsh
350322
run: |
351323
# PSScriptAnalyzer is already installed on GitHub runners
324+
if ($env:RUNNER_NAME -notlike 'GitHub Actions*') {
325+
$repo = Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue
326+
if (-not $repo) {
327+
Register-PSRepository -Default -InstallationPolicy Trusted
328+
} else {
329+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
330+
}
331+
Install-Module -Name PSScriptAnalyzer -Force
332+
}
352333
353334
# To see a list of available rules, run the following command:
354335
# Get-ScriptAnalyzerRule | Format-List

0 commit comments

Comments
 (0)