GitHub Actions gotcha: Workflows won’t run for pull request events if the pull request has a merge conflict.

Say you have a GitHub actions workflow set up to run on pull_request events with an activity type matching opened or closed:

# ./github/workflows/example-workflow.yaml
on:
  # Run on pull request opened or closed
  pull_request:
    types: [opened,closed]

Despite this, you may encounter strange behaviour, where the workflow does not trigger when closing a pull request 1.

This is a documented quirk in the GitHub actions implementation; Workflows will not run on pull_request activity if the pull request has a merge conflict2.

Solution

The Solution is use the pull_request_target event, which will always run. Even if the pull request has a merge conflict.

# ./github/workflows/example-workflow.yaml
on:
  # Run on pull request opened
  pull_request:
    types: [opened]
  # Run on pull request closed (even when there are merge conflicts)
  pull_request_target:
    types: [closed]

Be aware of the security implications of using pull_request_target though.

Note: Combining pull_request_target workflow trigger with checkout of an untrusted PR is dangerous and may lead to repository compromise.

Review the GitHub secure use reference before using this event in a public repository.