Home > Software engineering >  GitHub Actions Running Twice on Merge of PR
GitHub Actions Running Twice on Merge of PR

Time:11-29

I have a GitHub action with the following triggers:

name: Continuous Integration

on:
  schedule:
    - cron: "0 */3 * * *"
  push:
    branches:
      - master
      - preview
  pull_request:
    types: [ opened, synchronize, reopened ]
    branches:
      - master
      - preview

It seems to be running twice when a PR is merged in - I see the following: enter image description here AND enter image description here

I would expect only to see the one for Push to Preview (because I have the event type for PR as only opened, synchronized, and reopened).

How can I get my PRs to only build once when merging?

CodePudding user response:

As explained in this POST (and thread) on the Github Community.

You can achieve what you want using this trigger condition:

on:
  pull_request:
    types: [closed]

And then use this if condition in your job to guarantee it will run only if the PR has been merged:

jobs:
  build:
    if: github.event.pull_request.merged == 'true'
    steps:
      ...
  • Related