Ask Your Question
2

What is the method for detecting a pull request event that pertains to a particular branch in github actions?

asked 2023-05-18 13:56:42 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-18 14:19:02 +0000

woof gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-18 13:56:42 +0000

Seen: 12 times

Last updated: May 18 '23