ci/github-script/prepare: classify branches

This commit is contained in:
Wolfgang Walther
2025-08-18 21:53:55 +02:00
parent 9caf455441
commit 4220a03df8
2 changed files with 19 additions and 23 deletions

View File

@@ -23,8 +23,8 @@ jobs:
prepare: prepare:
runs-on: ubuntu-24.04-arm runs-on: ubuntu-24.04-arm
outputs: outputs:
baseBranch: ${{ steps.branches.outputs.base }} baseBranch: ${{ steps.prepare.outputs.base }}
headBranch: ${{ steps.branches.outputs.head }} headBranch: ${{ steps.prepare.outputs.head }}
mergedSha: ${{ steps.prepare.outputs.mergedSha }} mergedSha: ${{ steps.prepare.outputs.mergedSha }}
targetSha: ${{ steps.prepare.outputs.targetSha }} targetSha: ${{ steps.prepare.outputs.targetSha }}
systems: ${{ steps.prepare.outputs.systems }} systems: ${{ steps.prepare.outputs.systems }}
@@ -44,26 +44,6 @@ jobs:
core, 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 - name: Determine changed files
id: files id: files
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1

View File

@@ -1,3 +1,5 @@
const { classify } = require('../supportedBranches.js')
module.exports = async ({ github, context, core }) => { module.exports = async ({ github, context, core }) => {
const pull_number = context.payload.pull_request.number const pull_number = context.payload.pull_request.number
@@ -20,6 +22,8 @@ module.exports = async ({ github, context, core }) => {
continue continue
} }
const { base, head } = prInfo
let mergedSha, targetSha let mergedSha, targetSha
if (prInfo.mergeable) { if (prInfo.mergeable) {
@@ -39,7 +43,7 @@ module.exports = async ({ github, context, core }) => {
targetSha = ( targetSha = (
await github.rest.repos.compareCommitsWithBasehead({ await github.rest.repos.compareCommitsWithBasehead({
...context.repo, ...context.repo,
basehead: `${prInfo.base.sha}...${prInfo.head.sha}`, basehead: `${base.sha}...${head.sha}`,
}) })
).data.merge_base_commit.sha ).data.merge_base_commit.sha
} }
@@ -52,6 +56,18 @@ module.exports = async ({ github, context, core }) => {
core.setOutput('systems', require('../supportedSystems.json')) 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 return
} }
throw new Error( throw new Error(