Workflow is triggered in pull_request and push but fails on pull_request

I have a CI action to run tests on my repo for every pull request that is open or every push to a branch. I did it this way so we can have the tests running on a pushed branch even if a PR is not opened yet.

However, if a commit is pushed and a PR created right after, the action is triggered twice which is not very smart. I found this action that cancels previous running workflows in that branch but when both are triggered and one is cancelled I always get a notification email which is annoying…

It has been working well so far but now, the pull_request workflow fails and the push passes. Before I didn’t get both showing in the PR and now it does. Also, if I re-run the PR jobs, they fail again but the push workflow always passes.

Is there a smarter way to have this CI be triggered on PR and/or pushes to branches (with or without a PR open)?

on:
  pull_request:
    types: [opened]

  push:
    branches:
      - "*"
      - "!master"
      - "!staging"

image

I ended up doing this:

It kinda depends how much effort you’re willing to invest.

With enough pre magic, you might be able to get a skipped status instead of a green check. But, I’ve decided that the green check is much better than the red x (which turned out to be incredibly annoying as you’ve also discovered).