Rerun on base-branch change

Hi,

We use GitHub Actions for CI on pull requests. It works pretty great! I hit an edge-case on when actions run that I did not expect or fully understand.

We have our actions set only to run when the base branch on a PR is master. I had PR#1 with a base branch of master in review, and built PR#2 off of that with more code while I waited. I merged PR#1, then changed the base branch of PR#2 to master. I merged PR#2 without paying close enough attention: it did not have the full set of actions run and when they were run on master the branch was red.

Do actions not trigger to run when the base branch is changed, or did I do something else incorrectly?

Thanks for any help!

1 Like

@gumpt,
The below points may be able to help you understand:

  1. When you open a PR to merge some changes from a branch to another branch (suppose from feature1 to master), GitHub will only reference the workflow YAML file that from feature1 branch to run the workflow.

  2. In the workflow YAML file, if you do not specify activity types for the pull_request event, by default, the workflow only runs when the pull_request’s activity type is opened, synchronize, or reopened.

pull_request:
  branches: 
    - master
  1. When you change the base branch of an Open PR, the pull_request’s activity type is edited. So if you want the change of the PR’s base branch can trigger the workflow, you need to add the activity type edited to the pull_request event in the workflow YAML file.
pull_request:
  types: [opened, synchronize, edited, reopened]
  branches: 
    - master
  1. You should avoid the conflicts on the PR as much as possible. If have conflicts, solve them with the latest code you require.

  2. Before merging the PR (suppose from feature1 to master), you also should make sure the source branch feature1 has been up to date with the base branch master. If the feature1 is out-of-data with master, you need to update branch feature1 to marge the latest changes from master into feature1.
    ◆ If you have enabled branch protection rule for master, you can check the option " Require branches to be up to date before merging" when enabling required status checks. Then you can see the “Update branch” button on the PR, if the source branch is out-of-data with the base branch.


    ◆ You also can execute the “Update a pull request branch” API to update the source branch.

1 Like