From 57946939e2227bfc159b74fc9a3d87c0df45c3ab Mon Sep 17 00:00:00 2001 From: Scott Cranfill Date: Wed, 17 Sep 2025 17:50:41 -0400 Subject: [PATCH] Restore example of conditional logic in expressions --- .../reference/workflows-and-actions/expressions.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/content/actions/reference/workflows-and-actions/expressions.md b/content/actions/reference/workflows-and-actions/expressions.md index 5efa6184856e..f89a80af8da8 100644 --- a/content/actions/reference/workflows-and-actions/expressions.md +++ b/content/actions/reference/workflows-and-actions/expressions.md @@ -83,6 +83,19 @@ env: {% data variables.product.prodname_dotcom %} provides a way to create conditional logic in expressions using binary logical operators (`&&` and `||`). This pattern can be used to achieve similar functionality to the ternary operator (`?:`) found in many programming languages, while actually using only binary operators. +### Example + +{% raw %} + +```yaml +env: + MY_ENV_VAR: ${{ github.ref == 'refs/heads/main' && 'value_for_main_branch' || 'value_for_other_branches' }} +``` + +{% endraw %} + +In this example, we're using a combination of `&&` and `||` operators to set the value of the `MY_ENV_VAR` environment variable based on whether the {% data variables.product.prodname_dotcom %} reference is set to `refs/heads/main` or not. If it is, the variable is set to `value_for_main_branch`. Otherwise, it is set to `value_for_other_branches`. It is important to note that the first value after the `&&` must be truthy. Otherwise, the value after the `||` will always be returned. + ## Functions {% data variables.product.prodname_dotcom %} offers a set of built-in functions that you can use in expressions. Some functions cast values to a string to perform comparisons. {% data variables.product.prodname_dotcom %} casts data types to a string using these conversions: