Does a pull_request merge always trigger the push event?

Hello all,

My intention is to trigger a CI workflow whenever files in master change.

Initially I defined the following triggers:

on:
  # Trigger on PR close
  pull_request:
    types: [closed]
    paths:
      - 'src/**'
      - 'modules/**'
    branches:
      - master

  # Trigger on push to master
  push:
    branches:
      - master
    paths:
      - 'src/**'
      - 'modules/**'

When I do this every PR close with changes triggers the job twice, which I did not expect.

Does a PR close with changes always trigger a push event?

Hi @actuallymentor ,

According to the configured events for your workflow, it is normal that the workflow was triggered twice.

Once the changes are merged to master branch via the PR, the PR will be closed automatically, so the event on.pull_request.closed will trigger the workflow once. Because of having changes are pushed to master branch, the event on.push will trigger the workflow once.

That’s why the workflow will be triggered twice.

If you want the workflow is triggered only when some changes are pushed to master branch, you just need to setup the push event for your workflow, and without pull_request event.

on:
 push:
   branches:
     - master
   paths:
     - 'src/**'
     - 'modules/**'
2 Likes

So to summarize: yes an ‘on.pull_request.close’ always triggers a ‘push’ event

1 Like

No, because a pull request can be closed without merging it and so there would be no push event in that case.