GitHub Actions: Passing Boolean input variables to reusable workflow_call

Sohail Rashid
3 min readFeb 25, 2022

--

GitHub Actions is an intriguing choice for developing, testing, and deploying all within a single platform. It is one of the fastest-growing tools and you or your organization might have decided to use it across all your projects. However, once you start building complex pipelines you will soon realize that GA has its limitations. Some known limitations are using nested reusable workflows or being able to resume/retry a specific job at a certain stage in the pipeline.

While most of these features are in GA’s roadmap for the coming releases but

you are not here to learn about the limitations and roadmaps of GA. You are here trying to figure out why can’t you pass a simple Boolean input variable into a reusable workflow_call

I felt the pain when I was working on a pipeline that was leveraging workflow_call as a reusable template that could be called with many workflow_dispatch(s). I was able to gather some info and make it work and I hope sharing here will save you some time.

There are two major pain points to consider when trying to pass Boolean or any type of input variable to a workflow_call

Input context for workflow_dispatch and workflow_call are not the same

for workflow_dispatch you need to use:

and for workflow_call you need to use:

Inconsistent input context is not intuitive and the errors are not descriptive enough so you will need to dig the documentation to know this.

Now, that we have figured out the inconsistent input context between workflow_dispatch and workflow_call your pipeline is still not able to recognize the actual value of the Boolean you are trying to pass to the reusable workflow_call (mostly defaults to false).

This brings us to the second pain point

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 will throw exceptions

reusable workflow_call treats Booleans as an actual Boolean

Let’s go through a working example that uses reusable workflow_call as a base template and a workflow_dispatch to call it.

.github/workflows/resusable_workflow.yml

You can see that the input Booleans are defined and later in the if statements [line 29,38] they are evaluated against Boolean expression.

Now, let’s build the dispatcher

.github/workflows/dispatcher.yml

Notice that the inputs are still Boolean but the way workflow_dispatch input is referenced and passed to the reusable workflow_call [line 21,22] is to read the input variable using github.event and either evaluate the input to a Boolean expression or use fromJSON to cast the string to an actual Boolean value that the workflow_call will understand.

I hope this helped you identify and mitigate the inconsistency between the input context of workflow_dispatch and workflow_call specifically working with Boolean variables. Cheers!

--

--