Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange boolean evaluation in GitHub actions

I'm trying to understand boolean expressions in GitHub actions. The manual gives the following example of literals of different types, including boolean as ${{ false }} and ${{ true }}.

Following their lead I use the following step with an env section that sets VARF to false and VART to true and then in the run key has some test output:

  - name: Var test
    env:
      VARF: ${{ false }}
      VART: ${{ true }}
    run: |
      echo "VART=${{ env.VARF }}"
      echo "VART=${{ env.VART }}"
      echo "VARF && VART=${{ env.VARF && env.VART }}"
      echo "VARF || VART=${{ env.VARF || env.VART }}"
      echo "!VARF=${{ ! env.VARF }}"
      echo "!!VART=${{ !! env.VART }}"

The output is as follows:

VART=false
VART=true
VARF && VART=true
VARF || VART=false
!VARF=false
!!VART=true

The plain output is as expected, showing true and false. The output of the && and || operators is the opposite of expected, giving false && true == true and false || true == false. The output of ${{ ! env.VARF }} is false when I'd expect true.

What's going on here? Possibly variables in the env context get coerced to strings, but that still doesn't explain all the results.

like image 998
BeeOnRope Avatar asked Sep 04 '26 19:09

BeeOnRope


1 Answers

There is some inconsistency between the input context (dispatch_workflow vs workflow_call) and the way booleans are treated by GitHub Actions. I have a short write-up on this. Hope you find this helpful

GitHub Actions: Passing Boolean input variables to reusable workflow_call

like image 143
Sohailra Avatar answered Sep 07 '26 13:09

Sohailra