workflows/check: use regular checkout

The filtered checkout we used before was a nice idea, but only worked
for small numbers of commits in a PR. It would fetch the whole history
initially, but only fetch objects on demand. This turns out to be much
too slow in a PR with 18 commits, regularly hitting the 10 minute
timeout, even when running it locally.

The new approach uses regular checkouts again. In contrast to the old
style, before we switched to the filtered checkout, this only fetches
exactly the commits we need - and all of them at once. This is
significantly faster than both other approaches, and scales much better.
A bigger number of commits doesn't have much of an effect, if any at
all.
This commit is contained in:
Wolfgang Walther
2025-08-13 13:53:14 +02:00
parent 051775fe0c
commit 0dff5ad6c5
2 changed files with 32 additions and 5 deletions

View File

@@ -38,13 +38,13 @@ jobs:
permissions:
pull-requests: write
runs-on: ubuntu-24.04-arm
timeout-minutes: 10
timeout-minutes: 3
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
filter: tree:0
path: trusted
sparse-checkout: |
ci/github-script
- name: Install dependencies
run: npm install bottleneck

View File

@@ -22,7 +22,7 @@ module.exports = async function ({ github, context, core, dry }) {
'?pr=' +
pull_number
async function handle({ sha, commit }) {
async function extract({ sha, commit }) {
// Using the last line with "cherry" + hash, because a chained backport
// can result in multiple of those lines. Only the last one counts.
const match = Array.from(
@@ -68,6 +68,14 @@ module.exports = async function ({ github, context, core, dry }) {
message: `${original_sha} given in ${sha} not found in any pickable branch.`,
}
return {
sha,
commit,
original_sha,
}
}
function diff({ sha, commit, original_sha }) {
const diff = execFileSync('git', [
'-C',
__dirname,
@@ -121,7 +129,26 @@ module.exports = async function ({ github, context, core, dry }) {
pull_number,
})
const results = await Promise.all(commits.map(handle))
const extracted = await Promise.all(commits.map(extract))
const fetch = extracted
.filter(({ severity }) => !severity)
.map(({ sha, original_sha }) => [ sha, original_sha ])
.flat()
if (fetch.length > 0) {
// Fetching all commits we need for diff at once is much faster than any other method.
execFileSync('git', [
'-C',
__dirname,
'fetch',
'--depth=2',
'origin',
...fetch,
])
}
const results = extracted.map(result => result.severity ? result : diff(result))
// Log all results without truncation, with better highlighting and all whitespace changes to the job log.
results.forEach(({ sha, commit, severity, message, colored_diff }) => {