How do you compare semantic versions or do arithmetic in expressions?
AdvancedConceptContexts, Expressions, Env & Outputs
Answer
You do not: expressions have no arithmetic or version comparison functions, and numeric comparison of '1.10' vs '1.9' gives the wrong answer. Do it in a step with real tools and expose the result as an output:
if [ "$(printf '%s\n' "$CURRENT" "$NEW" | sort -V | tail -1)" = "$NEW" ]; then
echo "is_newer=true" >> "$GITHUB_OUTPUT"
fi
Keep expressions to routing logic; put computation in scripts that you can test locally.
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?IntermediateHow do you write a ternary in GitHub Actions expressions?IntermediateWhat do `contains`, `startsWith`, `endsWith`, `format` and `join` do?BeginnerWhat are object filters (`.*`) and how are they useful?Intermediate