Skip to content

Commit

Permalink
feat(actions-set-shas): When in pull requests, use target branch
Browse files Browse the repository at this point in the history
BREAKING CHANGE: In PR's the target of the PR is now used instead of main branch.
  • Loading branch information
TriPSs committed May 15, 2024
1 parent e39a3fd commit dcb863f
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions actions/set-shas/src/set-shas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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()
})
Expand Down

0 comments on commit dcb863f

Please sign in to comment.