Skip to content

Incorrect info about expression syntax for if conditionals #3001

Closed
@jidicula

Description

@jidicula

What article on docs.github.com is affected?

https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#about-contexts-and-expressions

What part(s) of the article would you like to see updated?

There's a reusable ({% data reusables.github-actions.expression-syntax-if %}) in this document that contains the info:

When you use expressions in an if conditional, you may omit the expression syntax (${{ }}) because GitHub automatically evaluates the if conditional as an expression.

However, I just made a small example run with a job's if conditional like:

post-build:
     runs-on: ubuntu-latest
     needs: build
     if: !startsWith(needs.build.outputs.sha8, needs.build.outputs.short-sha)
     steps:
        # ...

and it failed with a syntax error in the if statement: The workflow is not valid. .github/workflows/release.yml: Unexpected tag '!startsWith(needs.build.outputs.sha8,' (see here).

The run succeeds when the expression is surrounded by ${{}}:

post-build:
     runs-on: ubuntu-latest
     needs: build
     if: ${{!startsWith(needs.build.outputs.sha8, needs.build.outputs.short-sha)}}
     steps:
        # ...

I'd fix this in a PR if I knew where to find the reusable, but it wasn't immediately transparent, so I'm submitting an issue instead. If anyone could point me to where {% data reusables.github-actions.expression-syntax-if %} is defined, I'll happily make a PR with the required changes. It seems that expressions must be explicitly indicated for evaluation if they contain any operators.

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    actionsThis issue or pull request should be reviewed by the docs actions teamcontentThis issue or pull request belongs to the Docs Content teamhelp wantedAnyone is welcome to open a pull request to fix this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions