Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Branch name incorrect on pull_request evented actions #13

Open
1 task done
ProTip opened this issue Mar 10, 2022 · 7 comments
Open
1 task done

Bug: Branch name incorrect on pull_request evented actions #13

ProTip opened this issue Mar 10, 2022 · 7 comments
Labels
bug Something isn't working

Comments

@ProTip
Copy link

ProTip commented Mar 10, 2022

Is there an existing issue for this?

  • 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 ProTip added the bug Something isn't working label Mar 10, 2022
@jschwanz
Copy link

jschwanz commented Apr 8, 2022

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

@paynerc
Copy link

paynerc commented May 4, 2022

Also experiencing this issue.

@chipallen2
Copy link

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:

@tomlau10
Copy link

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 Use head ref for PRs #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 😄

@samatcolumn
Copy link

This is also happening on issue_comment events

@dfernandezcalle
Copy link

Hasn't been resolved?
Is there any workaround?

@SashaRussu
Copy link

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 }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants