GitHub Actions: Passing Boolean input variables to reusable workflow_call

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!

--

--

--

Software Engineer, Big Data | ML | GCP | Azure

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Just remain aware of your habits and how you spend your time, and what habits start to increase in…

CS373 Fall 2020: Jennifer Suriadinata

Unity修正錯誤筆記06

How to Finally Find the Motivation You’ve Been Missing

Modular Health System in Unity

Java — How to get current Date and Time | Code Factory

Top 3 Open-Source Software Security Concerns and How to Mitigate Them

Cryptocurrency Portfolio Optimization In Python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sohail Rashid

Sohail Rashid

Software Engineer, Big Data | ML | GCP | Azure

More from Medium

Deploy Node Service on ECS Fargate

Connecting Robo 3T with DocumentDB outside AWS VPC.

Configure query base routing in AWS ALB ingress controller

Complete Guide of CICD pipeline using GitLab Runner to AWS EC2 instance with containerising the…