Access to target branch on push #25813
-
Is there any environment variable or context available that will identify the target branch for a push on a pull request? Eg. how would I set up a job that only runs for pushes on a PR with a specific target branch? In the following example, the target branch would be “master”: |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
By the way, it would also be useful to have access to diff (eg. a list of paths) generated for the action as described here: https://help.github.com/en/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#git-diff-comparisons |
Beta Was this translation helpful? Give feedback.
-
Is what I want “base.ref” as shown here: https://developer.github.com/v3/activity/events/types/#pullrequestevent ? If so, I will need access to this information in a push event. |
Beta Was this translation helpful? Give feedback.
-
Base ref will give you the information about the base of a pull request - yes. This information is provided to you in the github context. So you can use this either as a variable in your workflow, or an environment variable in workflow executions. For example:
Or to use this as a test for a step:
But if your goal is to create a workflow that only runs for pushes on a PR with a specific target branch then you can codify that in the trigger for the entire workflow:
|
Beta Was this translation helpful? Give feedback.
-
My original intent was to be able to derive a diff list of files for changed on any PR which is set to merge into a specific branch. I want this to essentially be able to implement my own path filtering logic, similar to how you can restrict actions to specific repository paths, except that I want my action to apply to the entire repository but execute different commands based on the diff list. Your suggestion will allow me to do this, thank you (although it would be nice if Github also provided the list they diff’d against in the context). One note: when using “pull_request” as the trigger instead of “push”, the SHA I get in ${{ github.sha }} does not seem to point to a valid commit. It seems to be referencing a commit on some internal pull request branch instead of the latest commit that triggered the pull request event (see: https://help.github.com/en/github/automating-your-workflow-with-github-actions/events-that-trigger-workflows#pull-request-event-pull_request) – that doesn’t seem very useful, how can I reference the commit that caused the trigger when using this event type? |
Beta Was this translation helpful? Give feedback.
-
Ah, the following works for me:
A bit confusing but it’s in there. Thanks for the tips! |
Beta Was this translation helpful? Give feedback.
-
Came across the same issue. Wouldn’t using |
Beta Was this translation helpful? Give feedback.
-
@mkorablin you can specify which PR events you care about: https://help.github.com/en/github/automating-your-workflow-with-github-actions/events-that-trigger-workflows#pull-request-event-pull_request By default, if you don’t specify any types, it will use opened , synchronize , or reopened. It’s not very clear from the documentation, but synchronize gets triggered when updates are pushed to the PR (eg: a new commit is pushed). |
Beta Was this translation helpful? Give feedback.
Base ref will give you the information about the base of a pull request - yes. This information is provided to you in the github context. So you can use this either as a variable in your workflow, or an environment variable in workflow executions. For example:
Or to use this as a test for a step:
But if your goal is to create a workflow that only runs for pushes on a PR with a specific target branch then you can codify that in the trigger for the entire workflow: