question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If condition are always evaluated as true when containing expression syntax inside

See original GitHub issue

Describe 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:

  1. create a workflow
  2. add an if condition with expression syntax ${{ ... }} as part of the condition (not wrapping the whole condition)
  3. 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

Bildschirmfoto 2021-06-25 um 15 31 17

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:50
  • Comments:33 (1 by maintainers)

github_iconTop GitHub Comments

39reactions
BuckinghamIOcommented, Apr 22, 2022

How can this still be an issue almost a year on? Kinda disappointed really as this is quite a fundamental part.

15reactions
raghuvarmabhcommented, Jul 26, 2022

I fixed like this

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found