How to use bash command in job.if

Hi all,

I have the following if expression:

jobs:
  test_pr:
    if:  github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && github.event.comment.body == 'retest')

What it basically does is that the job runs when the event name is pull request or when the issue comment is retest. So that works but the issue is that if i want to trim the github.event.comment.body and i don’t see a way to run a bash command or even use an action in the job.if

I thought about 2 solutions:

  • This job will be dependent on another job which makes the trimming in the build steps and i will be dependent on this job through the need context. This is nice but now when people look in the jobs tab they will see two jobs and this is confusing.

  • Add a step to normalize this value and then add the same if to every step which follows. This is not safe because i can forget the if in a new step i make.

The best way would be to run a bash command and use it inside the if but i don’t see it documented in any place. A regular expression command or trim function would also be nice but i don’t see it documented.

Is there another way to fix this?

Thanks

Running bash commands directly in an if condition is not supported. There are some workflow functions for checking strings, but they are pretty simple (contains, startsWith, endsWith). Maybe something like contains('retest', github.event.comment.body) would work? That’d also run if “retest” is part of a longer text or word, though.

If you need a check that’s too complex for the workflow functions the approach with two jobs seems like the best currently supported option to me.