xandermonkey
xandermonkey

Reputation: 4422

Github Action trigger job on feature branch when master branch is updated

I have a github action that checks that the version numbers in my DB migration files don't overlap (if we have migration 101_SomeThing, make sure we don't also have migration 101_SomeOtherThing).

I run this github action on pull requests against the merge commit to see if there is already a file on master that would conflict. However, this only runs when the PR gets updated... so, if there is another PR that is merged, and the existing PR doesn't get updated, it will show a passed check for what should be a fail.

For example:

  1. master: /migrations/100_SomeStuff
  2. feature/foo: /migrations/101_foo opens a PR
  3. feature/bar: /migrations/101_bar opens a PR
  4. feature/foo is merged
  5. feature/bar now has a passing check that should fail.

How do I trigger the action to re-run on step #5 in response to the event of step #4?

Upvotes: 1

Views: 934

Answers (1)

GoldFlsh
GoldFlsh

Reputation: 1334

Not really a github actions solution, but if you turn on this flag in your branch protections:

Require branches to be up to date before merging 

Then it will force branches to be updated before merging. Because foo was merged first, this means bar falls behind master, and it will fail this check.

The developer will then be forced to merge master into bar.

I assume your workflow file is setup to trigger if new commits are pushed to the PR. In that case, when the merge commit (or if they rebase, however the dev wants to handle it) is pushed to bar it will restart the workflow and re-run the checks and thus fail on your workflow.

Upvotes: 1

Related Questions