Only run actions on non draft pull request
Asked Answered
O

2

28

I have set Github actions to be skipped when a draft pull request has been created however it is not trigger when the pull request is ready for review. Is there any way to run the action when I draft PR is changed from draft to ready for review?

pull_request:
  types: ['opened', 'edited', 'reopened', 'synchronize', 'ready_for_review']

jobs:
 build:
    if: github.event.pull_request.draft == 'false'
    runs-on: ubuntu-latest
Oriya answered 12/7, 2021 at 14:22 Comment(1)
Changing github.event.pull_request.draft == 'false' to github.event.pull_request.draft == false makes it work.Confucianism
S
43

pull_request.draft is a boolean, but you're treating it as a string, so the types in your comparison don't match.

According to the docs, the operands are coerced to numbers in this case: the left-hand side (boolean) becomes 1 if true and 0 if false; the right-hand side (string) becomes NaN, so your if statement will never evaluate to true.

To fix, drop the quotes:

    if: github.event.pull_request.draft == false

This can be shortened using the negation operator !, but because ! is special for YAML, the value has to be quoted:

    if: '! github.event.pull_request.draft'
Skelp answered 12/7, 2021 at 14:36 Comment(0)
U
4
if: github.event.pull_request.draft == false

This answer by Benjamin is 100% correct. However, there are drawbacks explained in https://github.com/orgs/community/discussions/25722 , so I see a fellow developer

types: [opened, synchronize, reopened, ready_for_review]

jobs:
  fail_if_pull_request_is_draft:
    if: github.event.pull_request.draft == true
    runs-on: ...
    steps:
        run: exit 1

  get_changes:
    runs-on: ...
    if: github.event.pull_request.draft == false
Unsphere answered 12/2, 2024 at 14:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.