trigger-circleci-pipeline-action
trigger-circleci-pipeline-action copied to clipboard
Bug: Branch name incorrect on pull_request evented actions
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
I hit this issue today attempting to setup a trigger on specific PR activity.
Also experiencing this issue.
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:
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 🤦 )
-
it doesn't support
pull_request_target
event- we are migrating our repo to use
pull_request_target
instead ofpull_request
as the latter one will not trigger when there is merge conflict while the first one will always trigger - however the
context.ref
inpull_request_target
will be thepr base branch
(i.e. not starting withrefs/pull/
) so current detection code is not working
- we are migrating our repo to use
-
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 ☹️
- while this ref (commit sha) is correct, the display name is the source branch
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 returnspull/${prNum}/head
(i believe that the pr number can be extracted bypayload.pull_request.number
related github doc) -
merge
=> the gha's default referencepull/${prNum}/merge
-
head_ref
=> logic in #16 (can also be the default behavior when not passing thepr-branch-mode
param to be backward compatible)
-
in this way it can support way more use cases 😄
This is also happening on issue_comment
events
Hasn't been resolved? Is there any workaround?
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 }}