How not to trigger a workflow by pushing a merge commit?

My workflow is triggered by both push and pull_request events.

Merging changes from a pull request fires a push event, which means the workflow runs again for a merge commit. This seems redundant.
Is there a way not to run the workflow on merge?

When a push is from the merge of a PR, after the PR merged, on the target branch, it will automatically generate a head commit with the commit message looks like as " Merge pull request #<PR_ID> from <source_branch>".

You can use the property  github.event.head_commit of github context to access the  head_commit  object. And you also can use the property  github.event.head_commit.message  to view the message of the head commit.

So you can try using the if conditional like as below to skip executing all the jobs in your workflow.

if: (github.event_name == 'push' && contains(toJSON(github.event.head_commit.message), 'Merge pull request ') == false)
1 Like


I did it without toJSON and with ! instead of == false.