From dcb863f3ee2663caf2671059d203d96a494cd94c Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Wed, 15 May 2024 17:55:49 +0200 Subject: [PATCH] feat(actions-set-shas): When in pull requests, use target branch BREAKING CHANGE: In PR's the target of the PR is now used instead of main branch. --- actions/set-shas/src/set-shas.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/actions/set-shas/src/set-shas.ts b/actions/set-shas/src/set-shas.ts index 80d67066..52cd37b4 100644 --- a/actions/set-shas/src/set-shas.ts +++ b/actions/set-shas/src/set-shas.ts @@ -5,22 +5,14 @@ import { execCommand } from './utils/exec' async function run() { try { - // Get all options - const mainBranchName = core.getInput('main-branch-name') - core.info(`Got head sha "${github.context.sha}"`) let baseSha: string if (github.context.eventName === 'pull_request') { - core.info(`This is a pull request, get sha from "origin/${mainBranchName}"`) - console.log('github.context.payload.pull_request',github.context.payload.pull_request) - - baseSha = execCommand(`git merge-base origin/${mainBranchName} HEAD`, { - asString: true, - silent: !core.isDebug() - }) + core.info(`This is a pull request, get sha from "origin/${github.context.payload.pull_request.base.ref}"`) + baseSha = github.context.payload.pull_request.base.sha - core.info(`Got base sha "${baseSha}" from "origin/${mainBranchName}"`) + core.info(`Got base sha "${baseSha}" from "origin/${github.context.payload.pull_request.base.ref}"`) } else { const tag = execCommand('git describe --tags --abbrev=0', { @@ -31,7 +23,7 @@ async function run() { if (!tag) { core.warning(`No tags found, get base sha from origin!`) - baseSha = execCommand(`git rev-parse origin/${mainBranchName}~1`, { + baseSha = execCommand(`git rev-parse origin/${core.getInput('main-branch-name')}~1`, { asString: true, silent: !core.isDebug() })