0

I used to have a GitHub Actions workflow configured like this:

name: CI

on: [push, pull_request]

I was interested in switching my trigger to a PR approval instead, so I changed it to:

name: CI

on: [push, pull_request_review]

and in the job I added the following if element:

  myJob:
    name: Name of my job
    if: github.event_name == 'push' || github.event.review.state == 'approved'
    runs-on: ubuntu-22.04
    container: ...

However, the push trigger keeps working but the PR approval trigger does not.

I've also tried to define my on: setting in a more specific way, like this:

on:
  pull_request_review:
    types: [submitted]
  push:

But it doesn't do the trick. What else am I missing to make this work? I extracted all the above know-how from the documentation.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
knocte
  • 16,941
  • 11
  • 79
  • 125
  • You have an `||` (`or`), and you need `&&` instead – Fcmam5 Mar 08 '23 at 09:24
  • what? the trigger needs to happen when push OR pr_review – knocte Mar 08 '23 at 09:30
  • Your title says AND. If you need the `or` check that your workflow file with the second approach with (pull_request_review: types: [submitted]) is on the default branch – Fcmam5 Mar 08 '23 at 09:38
  • man, think about it; if I put && there, it's not going to be triggered ever because it cannot happen that `github.event.review.state == 'approved'` when the event_name is `push` – knocte Mar 08 '23 at 09:40

1 Answers1

0

Argh, it was not a code issue, but a settings issue! If the repo is private, this has to be enabled: https://github.com/user/repo/settings/actions -> option Run workflows from fork pull requests (if the repository is under an organization, it has to be enabled first in the organization settings; after that, it can be enabled in the repository settings).

knocte
  • 16,941
  • 11
  • 79
  • 125