From 5d53aab9e431502c955edb33bc55aea86d1f1042 Mon Sep 17 00:00:00 2001 From: "Y. Meyer-Norwood" <106889957+norwd@users.noreply.github.com> Date: Thu, 8 Jun 2023 09:58:37 +1200 Subject: [PATCH 1/6] Add explanation of ordinal comparison of strings using the `<` and `>` operators The `<` and `>` operators, and by extension the `<=` and `>=` operators, will behave unexpectedly when evaluating `steps.*.outputs.*` values, because these values will be compared as strings. So for example `'10000' > '2'` evaluates to false. This can lead to unexpected behaviour when used in `if: ${{ ... }}` conditional steps and should be documented. See also: https://github.com/orgs/community/discussions/57480 --- content/actions/learn-github-actions/expressions.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/content/actions/learn-github-actions/expressions.md b/content/actions/learn-github-actions/expressions.md index 736a8d6bbf6d..ef825917a977 100644 --- a/content/actions/learn-github-actions/expressions.md +++ b/content/actions/learn-github-actions/expressions.md @@ -78,7 +78,7 @@ env: | Operator | Description | | --- | --- | | `( )` | Logical grouping | -| `[ ]` | Index +| `[ ]` | Index | | `.` | Property de-reference | | `!` | Not | | `<` | Less than | @@ -90,6 +90,16 @@ env: | `&&` | And | | \|\| | Or | +{% data variables.product.prodname_dotcom %} performs loose ordinal comparisons. + +* If the value is a string, as may be the case for outputs from previous steps in a workflow, the `<` and `>` operators will compare the values in ASCII-betical order. + | Expression | Result | Explanation | + | --- | --- | --- | + | `'a' < 'b'` | `true` | `'a'` is `61` in ASCII and is less than `'b'` which is `62` in ASCII | + | `'d' < 'c'` | `false` | `'d'` is `64` in ASCII and is not less than `'c'` which is `63` in ASCII | + | `'15' < '9'` | `true` | The first character, `'1'`, is `31` in ASCII and is less than `'9'` which is `39` in ASCII, even though `15` is not less than `9` when evaluated as numbers instead of strings. | + | `fromJSON('15') < fromJSON('9')` | `false` | The `fromJSON()` function parses `'15'` and `'9'` as numbers, and `15` is not less than `9`. | + {% data variables.product.prodname_dotcom %} performs loose equality comparisons. * If the types do not match, {% data variables.product.prodname_dotcom %} coerces the type to a number. {% data variables.product.prodname_dotcom %} casts data types to a number using these conversions: From 246a16d471f0633398255c8a5c7a5f564f5b276c Mon Sep 17 00:00:00 2001 From: "Y. Meyer-Norwood" <106889957+norwd@users.noreply.github.com> Date: Fri, 9 Jun 2023 06:40:18 +1200 Subject: [PATCH 2/6] Add new line to separate table from paragraph This fixes a rendering problem. --- content/actions/learn-github-actions/expressions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/content/actions/learn-github-actions/expressions.md b/content/actions/learn-github-actions/expressions.md index ef825917a977..bd6df7a164fb 100644 --- a/content/actions/learn-github-actions/expressions.md +++ b/content/actions/learn-github-actions/expressions.md @@ -93,6 +93,7 @@ env: {% data variables.product.prodname_dotcom %} performs loose ordinal comparisons. * If the value is a string, as may be the case for outputs from previous steps in a workflow, the `<` and `>` operators will compare the values in ASCII-betical order. + | Expression | Result | Explanation | | --- | --- | --- | | `'a' < 'b'` | `true` | `'a'` is `61` in ASCII and is less than `'b'` which is `62` in ASCII | From 825ca93d2a8df749ca62fc5217743534f53eb8a2 Mon Sep 17 00:00:00 2001 From: "Y. Meyer-Norwood" <106889957+norwd@users.noreply.github.com> Date: Wed, 28 Jun 2023 10:46:08 +1200 Subject: [PATCH 3/6] Create expressions-syntax-evaluation.md --- data/reusables/actions/expressions-syntax-evaluation.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 data/reusables/actions/expressions-syntax-evaluation.md diff --git a/data/reusables/actions/expressions-syntax-evaluation.md b/data/reusables/actions/expressions-syntax-evaluation.md new file mode 100644 index 000000000000..475e55441781 --- /dev/null +++ b/data/reusables/actions/expressions-syntax-evaluation.md @@ -0,0 +1 @@ +You need to use specific syntax to tell {% data variables.product.prodname_dotcom %} to evaluate an expression rather than treat it as a string. From 3b6bd666e1308f92ef05df161981ec215ef5ecb1 Mon Sep 17 00:00:00 2001 From: "Y. Meyer-Norwood" <106889957+norwd@users.noreply.github.com> Date: Wed, 28 Jun 2023 10:47:03 +1200 Subject: [PATCH 4/6] Use `expressions-syntax-evaluation.md` to explain step output typing --- .../actions/learn-github-actions/expressions.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/content/actions/learn-github-actions/expressions.md b/content/actions/learn-github-actions/expressions.md index 010b1046288e..f672e91f74c0 100644 --- a/content/actions/learn-github-actions/expressions.md +++ b/content/actions/learn-github-actions/expressions.md @@ -17,7 +17,7 @@ You can use expressions to programmatically set environment variables in workflo Expressions are commonly used with the conditional `if` keyword in a workflow file to determine whether a step should run. When an `if` conditional is `true`, the step will run. -You need to use specific syntax to tell {% data variables.product.prodname_dotcom %} to evaluate an expression rather than treat it as a string. +{% data reusables.actions.expressions-syntax-evaluation %} {% raw %} `${{ }}` @@ -96,12 +96,15 @@ env: * If the value is a string, as may be the case for outputs from previous steps in a workflow, the `<` and `>` operators will compare the values in ASCII-betical order. - | Expression | Result | Explanation | - | --- | --- | --- | - | `'a' < 'b'` | `true` | `'a'` is `61` in ASCII and is less than `'b'` which is `62` in ASCII | - | `'d' < 'c'` | `false` | `'d'` is `64` in ASCII and is not less than `'c'` which is `63` in ASCII | - | `'15' < '9'` | `true` | The first character, `'1'`, is `31` in ASCII and is less than `'9'` which is `39` in ASCII, even though `15` is not less than `9` when evaluated as numbers instead of strings. | - | `fromJSON('15') < fromJSON('9')` | `false` | The `fromJSON()` function parses `'15'` and `'9'` as numbers, and `15` is not less than `9`. | + {% note %} + + **Notes:** + - {% data variables.product.company_short %} ignores case when comparing strings. + - `steps..outputs.` evaluates as a string. {% data reusables.actions.expressions-syntax-evaluation %} For more information, see "[AUTOTITLE](/actions/learn-github-actions/contexts#steps-context)." + - {% data reusables.actions.expression-syntax-if %} For more information about `if` conditionals, see "[AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif)." + - For numerical comparison, the `fromJSON()` function can be used to convert a string to a number. For more information on the `fromJSON()` function, see "[fromJSON](#fromjson)." + + {% endnote %} {% data variables.product.prodname_dotcom %} performs loose equality comparisons. From 0ce3905a50fdc318af14f0b147ae20515f008cc4 Mon Sep 17 00:00:00 2001 From: "Y. Meyer-Norwood" <106889957+norwd@users.noreply.github.com> Date: Wed, 28 Jun 2023 12:16:15 +1200 Subject: [PATCH 5/6] Update content/actions/learn-github-actions/expressions.md Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com> --- content/actions/learn-github-actions/expressions.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/actions/learn-github-actions/expressions.md b/content/actions/learn-github-actions/expressions.md index f672e91f74c0..20b7fcf4689a 100644 --- a/content/actions/learn-github-actions/expressions.md +++ b/content/actions/learn-github-actions/expressions.md @@ -94,7 +94,6 @@ env: {% data variables.product.prodname_dotcom %} performs loose ordinal comparisons. -* If the value is a string, as may be the case for outputs from previous steps in a workflow, the `<` and `>` operators will compare the values in ASCII-betical order. {% note %} From fb01451fe798f7cab8b3321dee7d7ce751631ede Mon Sep 17 00:00:00 2001 From: Joe Clark <31087804+jc-clark@users.noreply.github.com> Date: Wed, 28 Jun 2023 10:33:00 -0700 Subject: [PATCH 6/6] Update content/actions/learn-github-actions/expressions.md --- content/actions/learn-github-actions/expressions.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/content/actions/learn-github-actions/expressions.md b/content/actions/learn-github-actions/expressions.md index 20b7fcf4689a..8eadc7d2c199 100644 --- a/content/actions/learn-github-actions/expressions.md +++ b/content/actions/learn-github-actions/expressions.md @@ -92,9 +92,6 @@ env: | `&&` | And | | \|\| | Or | -{% data variables.product.prodname_dotcom %} performs loose ordinal comparisons. - - {% note %} **Notes:**