How to trigger builds in github actions when the target branch is updated?

Viewed 33

I would like to ensure that merging branch X into master will yield a working build/test. Currently, when I run a build with the settings:

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

it only builds the pull request code, not the merged code. Proving this is easy: If master changes, it doesn't trigger a re-run of the PR builds, while it should. I want to guarantee 100% with CI that no merge will break master.

I dug into the documentation of github actions, and I can only say that I'm more confused now. The closest I found to what I want is changing to this:

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  pull_request_target:
    types: synchronize

And I did this change, but I'm not sure it does what I want it to do. Now I see two copies of the same builds, and I'm hoping that it's one merged and one not.

The documentation seems to introduce many terms that I never heard of before, like "base ref"... But aren't we talking about the target? What is base ref? Researching this got me nowhere.

https://github.com/orgs/community/discussions/24567

https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows

How can I achieve what I'm looking for, namely, retriggering CI when target branch is changed, and having a build of the supposedly merged code, to prevent breaking changes from ever reaching the target branch?

0 Answers
Related