Check branch name in if: statement having AND

I have a line like this in a step -
if: ${{ (matrix.coverity == true) && (github.head_ref == "coverity_scan") && (runner.os == "Linux") }}
which gives a syntax error at the location where I check if the branch is “coverity_scan”. How should I fix this?

I also tried -

- uses: nelonoel/branch-name@v1
- name: foo
  if: ${{ (matrix.coverity == true) && (BRANCH_NAME == "coverity_scan") && (runner.os == "Linux") }}
  run: ....

which gives the same error.

On which kind of event is the workflow supposed to run? I’m wondering if the issue is that github.head_ref is defined only for pull_request or pull_request_target. For other events github.ref is likely what you want.

String literals in GitHub Actions expressions need to be enclosed by single quote marks. Double quote marks are not supported. This should work syntactically:

if: matrix.coverity == true && github.head_ref == 'coverity_scan' && runner.os == 'Linux'

1 Like