On trigger two conditions

Hello,

Is it possible to use two on trigger conditions, such as:

on:
pull_request:
branches:
- master
paths:
- ‘/.src’
- '!.github/

push:
branches:
- master
paths:
- '
/.src’
- '!.github/

It looks like it passes the parsing, but does it behave as OR or AND condition?

Thanks!

Neither. :wink:

Either of the conditions will trigger the workflow separately, so kind of similar to OR, but you’ll get multiple runs if multiple events occur.

Those are very unrelated events. All events effectively happen in parallel.

My action has extra code that effectively ends a push event if it detects there’s an open pull request.

Workflow:

Action definition:

Code:

Those can be related events. For example I want to trigger pull_request or merge only if given path conditions are met. If pull_request and files changed in src/.c or merge and files change in src/.c.

Sorry, the original message have the code block messed up:

on:
  pull_request:
    branches:
      - master
    paths:
      - 'src/*.c'
      - '!.github/**'
  push:
    branches:
      - master
    paths:
      - 'src/*.c'
      - '!.github/**'

The code is clearer now, but unfortunately your question isn’t. The events and their filters would still be handled completely separately.

Sorry for being unclear. The question was about how two conditions per event behave in GitHub Actions, and you basically answered it.

1 Like

So, your question isn’t unreasonable, and afaict the documentation doesn’t spell this out:

So, if I were you, I’d file a bug asking them to clarify.

But note, there are two unrelated things you’re asking about, and that isn’t helpful.

  • If a workflow defines two events, both events are treated as reasons to run workflows, and those reasons are independent, if there’s a reason to run that workflow for that event, it will run the jobs with the event to the best of its ability. Independent of any other events that may also be applicable to the workflow. (This is effectively an “OR”.) From my perspective, (and I think airtower-luna’s,) this part is clear.

  • If a workflow defines, more than one oftypes, paths, and branches, I believe that’s an and, however none of the text makes this clear and none of the examples cover it:
    Workflow syntax for GitHub Actions - GitHub Docs
    There’s a hint that it’s an and in that the text describes using them to narrow things down, and it’d only make sense if they actually narrow things down.
    Note that it’s probably and at the category level (types, tags, branches, …) but it’s an or at the level beneath that (so any matching type, any matching tag, any matching branch). – It wouldn’t be unreasonable to file a bug about this side, just don’t mention multiple on: ... cases as that will lead back to the confusion above.

1 Like

Yes, I meant the part of which event(s) will trigger workflows. Path and branch filters within each event are AND, as far as I know. :slightly_smiling_face:

1 Like