Workflow YAML error when validation/parsing leading exclamation

When a conditional is not contained within the expression syntax ${{ }} and it begins with the “not” operator ! or !! i.e.

  - if: !contains(github.ref, 'master') 

the Action’s run will fail during parsing/validation:

You have an error in your yaml syntax on line 7

6   steps: 
7      - uses: some/innocent-action # <--error reported on this line
8      - if: !contains(github.ref, 'master')  # <-- should blow up col 26 or so
9        run: echo something

This took quite a while (hours) to chase down, as:

  • the line number in the error was incorrect
  • to my surprise the syntax passes my IDE yaml plugin as well as all of the Node.js based yaml linters and validation packages I’ve tried.
  • debugging by making small changes, pushing, and waiting for failure in Github services is slow.

When inside a workflow expression, it passes validation:

8. - if: ${{ !contains(github.ref, 'master') }}  # <- OK

I believe the 1.2 YAML spec reserves the ! and !! for node anchoring. But support or proper parsing for this doesn’t seem to be widely adopted.

The problem here is lies in Intellij IDEA’s (my IDE) YAML Plugin and it primitive linting, and the handful of yaml parsers for node which do not catch this. However, with the explicit suggestion in the Github Workflow expression docs that the ${{ }} may be omitted, and in wanting to make use of the workflow helper functions, keeping expressions sort, and needing a falsy assertion, I think this is going to cause a lot of heartache. Perhaps fixing the line # and returning:

Starting expression with Not(!) operator is not supported outside of expression syntax.

The if must not start with a hyphen.

This should work:

       - uses: some/innocent-action
         if: !contains(github.ref, 'master')
         run: echo something

Incorrect. The steps: node is a sequence where each item is a mapping. Mappings contain key value pairs in any order. And as I mentioned, the workflow is parsed successfully when the value of the if conditional is contained within the Github Actions expression sequence.