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.

Boolean inputs are not actually booleans

See original GitHub issue

Describe the bug

Boolean type inputs do not work as expected; they are strings instead of booleans, even when surrounded by ${{ }} (e.g. in a step’s if condition).

To Reproduce Steps to reproduce the behavior:

Run this workflow using the workflow dispatch, with the foo input checkbox not ticked:

name: Thingy

on:
  workflow_dispatch:
    inputs:
      foo:
        description: Whether to foo
        type: boolean
        required: false
        default: false

jobs:
  thingy:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    env:
      FOO: ${{ github.event.inputs.foo }}
    steps:
      - name: Check value
        run: |
          echo "The value is: $FOO"

      - name: Run if foo
        if: ${{ github.event.inputs.foo }}
        run: |
          echo "Foo!"

      - name: Don't run if foo  # Eh, I meant "Run if not foo"
        if: ${{ ! github.event.inputs.foo }}
        run: |
          echo "Foo!"

Expected behavior

When the input is false, the Run if foo step should be skipped , and the Don't run if foo step should run.

Runner Version and Platform

Version of your runner? 2.284.0

OS of the machine running the runner? ubuntu-latest (20.04.3)

What’s not working?

The value of github.event.inputs.foo is false, yet the Run if foo step runs and the Don't run if foo step is skipped.

image

Additional context

It is the same for a string input type or boolean input type (https://github.blog/changelog/2021-11-10-github-actions-input-types-for-manual-workflows/).

Only if: ${{ github.event.inputs.foo == 'true' }} works. So the input must be being treated as a string.

This goes against what the documentation says at https://docs.github.com/en/actions/learn-github-actions/expressions#about-expressions:

…evaluate an expression rather than treat it as a string.

${{ <expression> }}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:143
  • Comments:47 (10 by maintainers)

github_iconTop GitHub Comments

26reactions
mike-careycommented, Feb 16, 2022

Something that I also recently learned is that booleans are “strings” within workflow dispatches and composite actions but not reusable workflows.

For workflow_dispatch and composite action boolean inputs are actually strings:

if: inputs.my-boolean == 'true'

and

if: github.event.inputs.my-boolean == 'true'

will work.

However, for reusable workflows, the boolean is actually a boolean:

if: inputs.my-boolean == true

or

if: inputs.my-boolean

References

19reactions
ajaykncommented, Apr 7, 2022

👋 We are working on some efforts in unifying the inputs context and will address these issues in future. So it should behave like inputs.boolean == true instead of strings (“true”) We will update once rolled out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Boolean input not passed correctly to reusable workflow
The essence is that booleans sometimes actually behave as strings and have to be treated as such. Edit: Looking at this again, it...
Read more >
What is wrong with boolean parameters?
A boolean argument indicates the function has 2 different behaviors. These 2 behaviors are probably tangled together. And this just calls for more....
Read more >
Github Actions Passing Boolean to reusable workflow_call
workflow_dispatch Boolean inputs are not actually Booleans. workflow_dispatch reads Boolean inputs as string and if you try to evaluate them as Boolean it ......
Read more >
4.9 — Boolean values
Boolean variables are variables that can have only two possible values: true, and false. To declare a Boolean variable, we use the keyword...
Read more >
Conditionals with if/else & Booleans | AP CSP (article)
The condition is a Boolean expression: an expression that evaluates to either true or false . Boolean values are another type of data...
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