Skip to content

Commit a4dff61

Browse files
Clarify how to use a negated expression in an if statement (#28800)
Co-authored-by: Siara <[email protected]>
1 parent 3c7e291 commit a4dff61

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

content/actions/learn-github-actions/expressions.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@ Expressions are commonly used with the conditional `if` keyword in a workflow fi
2323
`${{ <expression> }}`
2424
{% endraw %}
2525

26-
{% data reusables.actions.expression-syntax-if %} For more information about `if` conditionals, see "[AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif)."
26+
{% note %}
2727

28-
{% data reusables.actions.context-injection-warning %}
28+
**Note**: The exception to this rule is when you are using expressions in an `if` clause, where, optionally, you can usually omit {% raw %}`${{`{% endraw %} and {% raw %}`}}`{% endraw %}. For more information about `if` conditionals, see "[AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif)."
2929

30-
### Example expression in an `if` conditional
30+
{% endnote %}
3131

32-
```yaml
33-
steps:
34-
- uses: actions/hello-world-javascript-action@e76147da8e5c81eaf017dede5645551d4b94427b
35-
if: <expression>
36-
```
32+
{% data reusables.actions.context-injection-warning %}
3733

3834
### Example setting an environment variable
3935

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
When you use expressions in an `if` conditional, you may omit the {% raw %}`${{ }}`{% endraw %} expression syntax because {% data variables.product.prodname_actions %} automatically evaluates the `if` conditional as an expression. However, this rule does not apply everywhere.
1+
When you use expressions in an `if` conditional, you can, optionally, omit the {% raw %}`${{ }}`{% endraw %} expression syntax because {% data variables.product.prodname_actions %} automatically evaluates the `if` conditional as an expression. However, this exception does not apply everywhere.
22

3-
You must use the {% raw %}`${{ }}`{% endraw %} expression syntax or escape with `''`, `""`, or `()` when the expression starts with `!`, since `!` is reserved notation in YAML format.
3+
You must always use the {% raw %}`${{ }}`{% endraw %} expression syntax or escape with `''`, `""`, or `()` when the expression starts with `!`, since `!` is reserved notation in YAML format. For example:
44

5-
Using the {% raw %}`${{ }}`{% endraw %} expression syntax turns the contents into a string, and strings are truthy. For example, `if: true && {% raw %}${{ false }}{% endraw %}` will evaluate to `true`.
5+
{% raw %}
6+
7+
```yaml
8+
if: ${{ ! startsWith(github.ref, 'refs/tags/') }}
9+
```
10+
11+
{% endraw %}

0 commit comments

Comments
 (0)