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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With