Use conditions in expressions

Hello, I have test output from first step:

{
version-changed: false // boolean
current-version: '"1"' // json string
}

Now I try use this values in if step block:

jobs:
  my_job:
    steps:
      - name: Test
        if: steps.version.outputs['version-changed'] || steps.version.outputs['current-version'] == '"1"'

And its work!
If I wraps to ${{ ... }} this also work perfectly.

But now I try use this expression in with block:

jobs:
  my_job:
    steps:
      - name: Test
         uses: ...
         with:
           param1: ${{ steps.version.outputs['version-changed'] || steps.version.outputs['current-version'] == '"1"' }}
           param2: ${{ steps.version.outputs['version-changed'] == true || steps.version.outputs['current-version'] == '"1"' }}

The value of param1 now is false, but param2 is true.
Why do I have different behavior?

Example: test · qRoC/github-expression@3c6685b · GitHub

1 Like

Outputs are strings, so steps.version.outputs['version-changed'] is actually 'false'. This string is a truthy value, therefore the expression evaluates to 'false' and the or-condition is simply ignored.

steps.version.outputs['version-changed'] == true compares 'false' == true, evaluating to false. The second condition is checked and it evaluates to true (so does the overall expression).

I suppose you could change the param1 expression in either of the following ways:

  • ${{ steps.version.outputs['version-changed'] == 'true' || steps.version.outputs['current-version'] == '"1"' }}
  • ${{ fromJSON(steps.version.outputs['version-changed']) || steps.version.outputs['current-version'] == '"1"' }}