From 5b6133762099874b2a9b2bc354c538b969aa1012 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Mon, 18 Aug 2025 21:53:55 +0200 Subject: [PATCH] ci/github-script/prepare: classify branches (cherry picked from commit 4220a03df8744ded7a6594a940a3316d4ff5e702) --- .github/workflows/pr.yml | 24 ++---------------------- ci/github-script/prepare.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index d22641c085ad..51b0d41ddf1d 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -23,8 +23,8 @@ jobs: prepare: runs-on: ubuntu-24.04-arm outputs: - baseBranch: ${{ steps.branches.outputs.base }} - headBranch: ${{ steps.branches.outputs.head }} + baseBranch: ${{ steps.prepare.outputs.base }} + headBranch: ${{ steps.prepare.outputs.head }} mergedSha: ${{ steps.prepare.outputs.mergedSha }} targetSha: ${{ steps.prepare.outputs.targetSha }} systems: ${{ steps.prepare.outputs.systems }} @@ -44,26 +44,6 @@ jobs: core, }) - - name: Determine branch type - id: branches - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - with: - script: | - const { classify } = require('./ci/supportedBranches.js') - const { base, head } = context.payload.pull_request - - const baseClassification = classify(base.ref) - core.setOutput('base', baseClassification) - core.info('base classification:', baseClassification) - - const headClassification = - (base.repo.full_name == head.repo.full_name) ? - classify(head.ref) : - // PRs from forks are always considered WIP. - { type: ['wip'] } - core.setOutput('head', headClassification) - core.info('head classification:', headClassification) - - name: Determine changed files id: files uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 diff --git a/ci/github-script/prepare.js b/ci/github-script/prepare.js index bd1457249a27..1f56a502ca8a 100644 --- a/ci/github-script/prepare.js +++ b/ci/github-script/prepare.js @@ -1,3 +1,5 @@ +const { classify } = require('../supportedBranches.js') + module.exports = async ({ github, context, core }) => { const pull_number = context.payload.pull_request.number @@ -20,6 +22,8 @@ module.exports = async ({ github, context, core }) => { continue } + const { base, head } = prInfo + let mergedSha, targetSha if (prInfo.mergeable) { @@ -39,7 +43,7 @@ module.exports = async ({ github, context, core }) => { targetSha = ( await github.rest.repos.compareCommitsWithBasehead({ ...context.repo, - basehead: `${prInfo.base.sha}...${prInfo.head.sha}`, + basehead: `${base.sha}...${head.sha}`, }) ).data.merge_base_commit.sha } @@ -52,6 +56,18 @@ module.exports = async ({ github, context, core }) => { core.setOutput('systems', require('../supportedSystems.json')) + const baseClassification = classify(base.ref) + core.setOutput('base', baseClassification) + core.info('base classification:', baseClassification) + + const headClassification = + base.repo.full_name === head.repo.full_name + ? classify(head.ref) + : // PRs from forks are always considered WIP. + { type: ['wip'] } + core.setOutput('head', headClassification) + core.info('head classification:', headClassification) + return } throw new Error(