Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To detect a pull request event that pertains to a particular branch in GitHub actions, you can use the on keyword in the workflow YAML file to specify the event trigger as follows:

on:
  pull_request:
    branches:
      - branch-name

This will trigger the workflow when a pull request is opened or updated that targets the specified branch (branch-name).

You can then use the github.event.pull_request.head.ref context variable in the workflow to get the name of the branch that the pull request is coming from. For example, you can use it in a conditional step like this:

- name: Build and Test
  if: github.event_name == 'pull_request' && github.event.pull_request.head.ref == 'branch-name'
  run: |
    # commands to build and test the code

This will only run the Build and Test step if the event was a pull request targeting the branch-name.