-
Notifications
You must be signed in to change notification settings - Fork 62.4k
feat: describe conditional values #31252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Automatically generated comment ℹ️This comment is automatically generated and will be overwritten every time changes are committed to this branch. The table contains an overview of files in the Content directory changesYou may find it useful to copy this table into the pull request summary. There you can edit it to share links to important articles or changes and to give a high-level overview of how the changes in your pull request support the overall goals of the pull request.
fpt: Free, Pro, Team |
@deemp Thanks so much for opening a PR! I'll get this triaged for review ✨ |
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 `truthy` (in [JavaScript sense](https://developer.mozilla.org/en-US/docs/Glossary/Truthy)), the step will run. All values are `truthy` except for `false`, `0`, `-0`, `0n`, `""`, `''`, `null`, `undefined`, `NaN`. You can evaluate an `!!<expression>` (e.g., in your browser console) to check whether the `<expression>` is `truthy`. For example, `!!"false"` produces `true`, so `"false"` is `truthy`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This... isn't correct at all.
The workflow is parsed in a string context (except for numerals and booleans), so JavaScript truthiness is irrelevant. There's no way to define a true JavaScript NaN
or undefined
in YML, you end up with the strings 'NaN'
or 'undefined'
. Nearly any string will evaluate true
.
In this workflow:
strategy:
matrix:
runme:
- NaN
- undefined
- yes
- no
- false
- 0
- 1
- -0
steps:
- name: true-path
if: matrix.runme
run: echo "${{ matrix.runme }} evaluates true"
- name: false-path
if: '! matrix.runme'
run: echo "${{ matrix.runme }} evaluates false"
...The only matrix.runme
values for which false-path
will be executed are false
and 0
. (And -0
, technically, but that's only because it's interpreted as 0
. There's no distinction in YAML.) All of the others will evaluate true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, null
is also a valid YAML primitive, and it will also evaluate false
.
Honestly, I think this is pretty well explained in the Literals section of the Expressions docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
I ran the suggested job (link). I can confirm that the falsy values are
false
,0
,-0
,""
,''
,null
. I can't see where these values are listed in the Literals section. What do you think about just extending theboolean
docs?Data type Literal value boolean
falsy ( false
,0
,-0
,""
,''
,null
) or truthy (true
and other non-falsy values) -
I believe it's necessary to mention in the
if
docs that it expects aboolean
and will run a step if theboolean
is truthy. BTW, the docs already mention atruthy
value (link), but don't explain it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the PR
This reverts commit 5917b79.
if
valueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for updating the docs, @deemp! I'll go ahead and get this pull request merged. ✨
Thanks very much for contributing! Your pull request has been merged 🎉 You should see your changes appear on the site in approximately 24 hours. If you're looking for your next contribution, check out our help wanted issues ⚡ |
Why:
Closes: #23795
I used this hidden knowledge in freckle/stack-action#35 and decided to document it.
What's being changed (if available, include any code snippets, screenshots, or gifs):
Check off the following:
I have reviewed my changes in staging, available via the View deployment link in this PR's timeline (this link will be available after opening the PR).
data
directory.For content changes, I have completed the self-review checklist.