Trigger workflow when pr is merged and closed (not only closed)

on:
  pull_request:
    types: [closed]

It works fine when github actions are required to get triggered when pr is merged and closed, but here the drawback is it still gets triggered when pr is closed (without merging)
So how to overcome this drawback?

Hi @AB-san, welcome to the GitHub Support Community! I don’t believe there’s a way you can do this inside the on block as we don’t fire a specific event for merged. However, you should be able to use an if conditional inside the job you want to run to filter on the pull_request.merged variable:

on:
  pull_request:
    types: [closed]

jobs:
  my-job:
    runs-on: ubuntu-latest
    if: ${{ github.event.pull_request.merged == true }}
    steps:
      ...
1 Like