trigger-circleci-pipeline-action icon indicating copy to clipboard operation
trigger-circleci-pipeline-action copied to clipboard

Bug: Branch name incorrect on pull_request evented actions

Open ProTip opened this issue 2 years ago • 7 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current behavior

Triggering branch: refs/pull/4781/merge

Minimum reproduction code

https://github.com/CircleCI-Public/trigger-circleci-pipeline-action

Steps to reproduce

No response

Expected behavior

Expect the branch name to be "correct". It must be obtained through different sources based on the event type that triggers the action:

https://www.techiediaries.com/get-current-branch-name-github-actions-github_ref-bash/

Further, sometimes it can be fetched from github.event.ref (for instance in the case of the delete event).

GitHub Action Version

1.0.4

Other

No response

ProTip avatar Mar 10 '22 00:03 ProTip

I hit this issue today attempting to setup a trigger on specific PR activity.

jschwanz avatar Apr 08 '22 21:04 jschwanz

Also experiencing this issue.

paynerc avatar May 04 '22 20:05 paynerc

Experiencing this issue on 1.0.4. Any update on this?

The branch in circleci says 'refs/pull/####/merge' instead of the actual source branch for the PR and then the SHA isn't valid and it throws this error:

fatal: reference is not a tree:

chipallen2 avatar May 24 '22 05:05 chipallen2

hi I come across this action library recently and noticed that #16 adds support for pull_request event however its use case is some what limited and does not fit our use cases 🤔 (and so we are still using some ugly custom code to extract the correct branch 🤦 )

  1. it doesn't support pull_request_target event

    • we are migrating our repo to use pull_request_target instead of pull_request as the latter one will not trigger when there is merge conflict while the first one will always trigger
    • however the context.ref in pull_request_target will be the pr base branch (i.e. not starting with refs/pull/) so current detection code is not working
  2. github.head_ref is a branch name unrelated to pr number

    • while this ref (commit sha) is correct, the display name is the source branch name and contains no pr information (the pr number to be exact)
    • and without the pr number, it is difficult (impossible) to tell which pr is triggering the workflow in the circleci's dashboard ☹️

I would suggest adding a pr-branch-mode action param

  • which only takes effect when context.eventName.startsWith("pull_request")
  • supports a few different mode like
    • head => get the pr number and returns pull/${prNum}/head (i believe that the pr number can be extracted by payload.pull_request.number related github doc)
    • merge => the gha's default reference pull/${prNum}/merge
    • head_ref => logic in #16 (can also be the default behavior when not passing the pr-branch-mode param to be backward compatible)

in this way it can support way more use cases 😄

tomlau10 avatar Jul 21 '22 10:07 tomlau10

This is also happening on issue_comment events

samatcolumn avatar Aug 03 '22 13:08 samatcolumn

Hasn't been resolved? Is there any workaround?

dfernandezcalle avatar Apr 20 '23 17:04 dfernandezcalle

Hasn't been resolved? Is there any workaround?

I resolved this by adding a TARGET_BRANCH.

jobs:
  trigger-circleci:
    runs-on: ubuntu-latest
    steps:
      - uses: CircleCI-Public/[email protected]
        env:
          CCI_TOKEN: ${{ secrets.CCI_TOKEN }}
          TARGET_BRANCH: ${{ github.event.pull_request.head.ref }}

SashaRussu avatar May 26 '23 12:05 SashaRussu