From 0dff5ad6c5eeeb0e767513edbf4c7d3afd9154cf Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Wed, 13 Aug 2025 13:53:14 +0200 Subject: [PATCH] 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. --- .github/workflows/check.yml | 6 +++--- ci/github-script/commits.js | 31 +++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 368a10eee78c..ece7a287eaae 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -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 diff --git a/ci/github-script/commits.js b/ci/github-script/commits.js index e5553c59ce7f..f22034ea788d 100644 --- a/ci/github-script/commits.js +++ b/ci/github-script/commits.js @@ -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 }) => {