skip to Main Content

I have workflow file that I want it to run on non-draft PRs and on every new commit to the PR.

So far, I have tried two ways:

  1. Using if statement
name: Test

on:
  pull_request:
    branches:
      - master

jobs:
  test:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest

This does not trigger workflow when PR converted to ready for review.

  1. Using types statement
name: Test

on:
  pull_request:
    branches:
      - master
    types:
      - ready_for_review

jobs:
  test:
    runs-on: ubuntu-latest

This does not trigger workflow when a new commit pushed to PR.

How can I add a condition so that my workflow runs on non-draft PRs and also all new commits?

2

Answers


  1. This is similar to another question.

    The answer in the other question suggests using

    if: ! github.event.pull_request.draft
    

    to check if the PR is a draft, since there might otherwise be some type confusion with booleans in GitHub Actions.

    Login or Signup to reply.
  2. In your first code block you leave the types as the default (opened, synchronize & reopened).
    In the second code block you only use the ready_for_review type.

    You can just combine the two:

    name: Test
    
    on:
      pull_request:
        types:
          - opened
          - synchronize
          - reopened
          - ready_for_review
    
    jobs:
      test:
        if: github.event.pull_request.draft == false
        # You could have ths version too - note the  single quotes:
        # if: '! github.event.pull_request.draft'
        name: Check PR is not a Draft
        runs-on: ubuntu-latest
        steps:
          - run: |
              echo "Non-draft Pull request change detected"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search