How to set a job to run when pushing to a PR branch?

As far as I can tell on: [pull_request] is not the right thing, because that triggers when doing various other actions on a pull request, such as requesting a review or closing it. on: [push] combined with if: github.event_name == 'pull_request' doesn’t seem to work. If I understand correctly, this is because they can’t both be true at the same time.

I’m starting to think I might’ve missed something, because there are heaps of people which seem to say that on: [pull_request] means “when pushing to a pull request branch”, but I can’t reconcile that with the documentation. I thought maybe the synchronize activity type might be related to pushes, but the official documentation doesn’t seem to have any details. This article seems to corroborate the common usage, but that’s the only one I could find.

This is related to another question (as a new user I’m not allowed to add any more links to this post) – basically I’m trying to figure out how to run jobs only when pushing to

  • a branch
  • for which there exists a pull request
  • which is open and
  • which is not a draft.
1 Like

What you are looking for is:

on:
  pull_request:
    types: [opened, synchronize, reopened]

Where synchronize means a change has been pushed to the PR branch.

Edit, per the GitHub docs: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#pull_request it looks like this is actually the default behavior:

Note: By default, a workflow only runs when a pull_request 's activity type is opened , synchronize , or reopened . To trigger workflows for more activity types, use the types keyword.

2 Likes

I do agree that the docs on this are not explicitly clear about. I had to look up what “synchronize” meant in this context. I just opened an issue to hopefully fix this: https://github.com/github/docs/issues/2257

1 Like