If condition are always evaluated as true when containing expression syntax inside
See original GitHub issueDescribe the bug An if condition in a step definition that includes expression syntax in condition body is always evaluated as false positive or is ignored.
Example workflow: https://github.com/dlavrenuek/test-workflow-if-condition/blob/master/.github/workflows/test.yml
name: test if conditions
on:
push:
branches: [master, test]
env:
TEST_BRANCH: "test"
EMPTY_VALUE: ""
jobs:
test-conditions:
runs-on: ubuntu-latest
steps:
- name: simple evaluation on master
if: github.ref == 'refs/heads/master'
run: echo "runs"
- name: simple evaluation on test
if: github.ref == 'refs/heads/test'
run: echo "runs"
- name: false positive with expression syntac evaluation
if: github.ref == 'refs/head/${{ env.TEST_BRANCH }}' # this condition is ignored or is evaluated as false positive
run: echo "runs"
- name: false positive with expression syntac evaluation
if: false && '${{ env.EMPTY_VALUE }}' # this condition is ignored or is evaluated as false positive
run: echo "runs"
Example run: https://github.com/dlavrenuek/test-workflow-if-condition/runs/2914408827?check_suite_focus=true
Example step definition:
- name: false positive with expression syntax evaluation
if: github.ref == 'refs/head/${{ env.TEST_BRANCH }}'
run: echo "runs"
In the example workflow the last two steps should not have been run, but they were
To Reproduce Steps to reproduce the behavior:
- create a workflow
- add an
if
condition with expression syntax${{ ... }}
as part of the condition (not wrapping the whole condition) - trigger the workflow
Expected behavior
- The if condition should be correctly evaluated.
- In case that the expression syntax is not supported as part of an
if
condition - an error should be thrown instead of silently ignoring it.
Runner Version and Platform
GitHub platform
What’s not working?
The steps are executed because of false positive evaluation of he if condition containing expression syntax
Issue Analytics
- State:
- Created 2 years ago
- Reactions:50
- Comments:33 (1 by maintainers)
Top Results From Across the Web
Review: Logic and if Statements (article)
We have many ways of creating conditional expressions that will evaluate to true or false , because we have many comparison operators.
Read more >If...Else Statement in C Explained
The block of code inside the if statement is executed is the condition evaluates to true. However, the code inside the curly braces...
Read more >Conditional branching: if, '?'
The if(...) statement evaluates a condition in parentheses and, if the result is true , executes a block of code. For example: let...
Read more >Why my condition is always true - javascript
For this reason, your condition is always true. JavaScript returns true for the second or expression because 'b' is always true.
Read more >If (Expression) - Syntax & Usage
The "if (expression)" statement specifies one or more statements to execute if an expression evaluates to true.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
How can this still be an issue almost a year on? Kinda disappointed really as this is quite a fundamental part.
I fixed like this