How do you write a ternary in GitHub Actions expressions?
IntermediateConceptContexts, Expressions, Env & Outputs
Answer
Use cond && a || b:
env:
REPLICAS: ${{ github.ref == 'refs/heads/main' && '3' || '1' }}
Trap: if a is falsy ('', 0, false, null), you always get b. ${{ x && 0 || 5 }} always returns 5. Use strings for such values, or restructure the condition.
More on Contexts, Expressions, Env & Outputs
List the available contexts and what each holds.BeginnerWhich contexts can you use in which keys? Give two examples that trip people up.AdvancedWhat are the expression operators and how do comparisons coerce types?IntermediateWhat do `contains`, `startsWith`, `endsWith`, `format` and `join` do?BeginnerWhat are object filters (`.*`) and how are they useful?IntermediateWhat do `toJSON` and `fromJSON` do, and give a real use of each?Intermediate