Github action combining if condition or writing it in Multiple lines

Hi all,
I have a very long if condition in Github action workflow. Can it be reduced in a lesser number of condition and if not, how to write it in multiple lines?

The command is:


      - name: Running all tests
        if: startsWith(github.event.comment.body, '/run-e2e-all') || startsWith(github.event.comment.body, '/run-e2e-first-test') || startsWith(github.event.comment.body, '/run-e2e-second-test') || startsWith(github.event.comment.body, '/run-e2e-third-test') || startsWith(github.event.comment.body, '/run-e2e-fourth-test') || startsWith(github.event.comment.body, '/run-e2e-fifth-test') || startsWith(github.event.comment.body, '/run-e2e-sixth-test') || startsWith(github.event.comment.body, '/run-e2e-seventh-test') || startsWith(github.event.comment.body, '/run-e2e-eighth-test') || startsWith(github.event.comment.body, '/run-e2e-nineth-test') || startsWith(github.event.comment.body, '/run-e2e-tenth-test')
        run: |
          echo "Hello all"

Please share if you have any thoughts on this.
Thanks!

@uditgaurav,
You can write like as the following:

- name: Running all tests
  if: |
    startsWith(github.event.comment.body, '/run-e2e-all') ||
    startsWith(github.event.comment.body, '/run-e2e-first-test') ||
    startsWith(github.event.comment.body, '/run-e2e-second-test') ||
    startsWith(github.event.comment.body, '/run-e2e-third-test') ||
    startsWith(github.event.comment.body, '/run-e2e-fourth-test') ||
    startsWith(github.event.comment.body, '/run-e2e-fifth-test') ||
    startsWith(github.event.comment.body, '/run-e2e-sixth-test') ||
    startsWith(github.event.comment.body, '/run-e2e-seventh-test') ||
    startsWith(github.event.comment.body, '/run-e2e-eighth-test') ||
    startsWith(github.event.comment.body, '/run-e2e-nineth-test') ||
    startsWith(github.event.comment.body, '/run-e2e-tenth-test')
  run: |
    echo "Hello all"

In the workflow YAML file, if you want to set value of an option (such as env.<VAR_NAME>, run, if) as multi-line text, you can generally use the ‘|’ character to declare.

1 Like