You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Conditional operator or function for expression syntax #409
I'd like some kind of conditional operation added to expression syntax. This can be an actual ternary operator (?:) or a built-in function (e.g., if(<condition>, <true-value>, <false-value>)).
Additional information
There is a workaround: using shell scripts to evaluate the condition, setting step outputs, and having other steps reference those outputs. But it would be much cleaner to have some kind of ternary / if/then/else / conditional branching built in to the expression syntax.
It seems, although not identical, <condition> && <true-value> || <false-value> works in most cases.
Reacted by aaronamm, Beshoy Girgis, Kevin Métivier, Pushpavel, Liam Nguyen, Juan José Albarracín, Ashlynne Mitchell, Vadim Markovtsev, Roman Scher, Noman Gul and 87 more
Reacted by Axel Heider and Evan Schallerer
Reacted by Steven B, Yuncheng Yang, Michel Daoust, Alexandr Evstigneev, Albert Mañosa, Vincent Le Quec, Jaume Balust, Thomas Evans, Thiago da Silva, Jose Aviles and 3 more
Reacted by Daniel Himmelstein, Cesar Manrique, Jordan Last, Geoffrey Martin-Noble, Gerhard Mostert, MJ Zhang, Michel Daoust, Steven Boutcher, Rashi Malhotra and z3phyr
on condition is that your first <true-value> must be true for this to work
Reacted by Dan Keenan, Brody McKee, Bruce MacNaughton, Edward Chernenko, aaronamm, Brad, Kyle Benesch, Yaakov Yisroel Kopstein, nemmyam, Evgeny and 236 more
Reacted by Tuahear, Mariana González Velarde, Kantonov, Kuba, Nakash Kumar, Ondřej Španěl, MJ Zhang, David, Subesh Bhandari 🇳🇵, Oliver Borchert and 38 more
Reacted by Justice Almanzar, Moshe Azaria and Thom
Also, I'm seeing errors like this when using non-boolean values as predicates in case:
The workflow is not valid. Error when evaluating 'run-name'. .github/workflows/my-workflow.yml (Line: 2, Col: 11): Error from function 'case': case predicate must evaluate to a boolean value
Note that in conditionals, falsy values (false, 0, -0, "", '', null) are coerced to false and truthy (true and other non-falsy values) are coerced to true.
Is there a reason that case doesn't coerce non-falsy values to true?
As for the boolean values, we intentionally require predicates to be booleans to avoid common failure scenarios that unintentionally or incorrectly rely on falsy coercions. I'll take a look to see how we can improve the docs in regards to that as well.
I see. I know an input (inputs context in workflows & actions) with no default value is falsy if it is not provided; is it equal to the empty string? In other words: instead of case(inputs.maybe-this-input-was-provided, 'thing A', 'thing B'), I should do case(inputs.maybe-this-input-was-provided != '', 'thing A', 'thing B')?
Activity
[-]Conditional operator or function[/-][+]Conditional operator or function for expression syntax[/+]ylemkimon commentedon Aug 16, 2020
Another alternative syntax could be:
like CircleCI.
ylemkimon commentedon Nov 15, 2020
It seems, although not identical,
<condition> && <true-value> || <false-value>works in most cases.molszanski commentedon Dec 30, 2020
Syntax:
${{ x && 'ifTrue' || 'ifFalse' }}fake ternary example
on condition is that your first
<true-value>must be true for this to workUse correct compiler command
Include Intel compiler and MPI in CI (#36)
TWiStErRob commentedon Jul 17, 2021
Example use case https://github.com/TWiStErRob/net.twisterrob.gradle/pull/136/files
Related StackOverflow: https://stackoverflow.com/a/68422069/253468
LaPeste commentedon Aug 26, 2021
The fact that in a year no one said a word about this, means that the team isn't interested in following up on this one?
34 remaining items
GitHub ternary operator doesn't handle the empty string (#10)
Fix ternary operator in github workflow (#2653)
salilsub commentedon Jan 30, 2026
Hi everyone, we just announced our new
casefunction which is adds conditionals for expressions.lpulley commentedon Jan 30, 2026
BTW it seems that this example from the
casedocs is not valid YAML:The
) }}is not indented, so is not considered part of theMY_ENV_VARvalue. Maybe this, with double quotes?lpulley commentedon Jan 30, 2026
Also, I'm seeing errors like this when using non-boolean values as predicates in
case:but the expressions docs say:
Is there a reason that
casedoesn't coerce non-falsy values totrue?AllanGuigou commentedon Jan 30, 2026
@lpulley we've fixed the invalid YAML in the docs,
Thanks for calling that out!
As for the boolean values, we intentionally require predicates to be booleans to avoid common failure scenarios that unintentionally or incorrectly rely on falsy coercions. I'll take a look to see how we can improve the docs in regards to that as well.
lpulley commentedon Jan 30, 2026
I see. I know an input (
inputscontext in workflows & actions) with no default value is falsy if it is not provided; is it equal to the empty string? In other words: instead ofcase(inputs.maybe-this-input-was-provided, 'thing A', 'thing B'), I should docase(inputs.maybe-this-input-was-provided != '', 'thing A', 'thing B')?ericsciple commentedon Mar 10, 2026
@lpulley 👍 the empty string check should work since empty string is also falsy
ericsciple commentedon Mar 10, 2026
Closing this issue since the
casefunction is released:chore: use GitHub case syntax instead of ternary "if" (dfinity#10139)
Don't pass --fail-commands-not-all-hit to validator if we don't run t…