We use the workflow_dispatch
trigger to run a GitHub Action manually. This also allows us to specify any inputs that we want to provide to the action at the time of running (link to documentation).
Take the below example where an imaginary workflow greets a person based on whether they prefer "Hello" or not as told by user. This would not work if the workflow parameter greetWithHello
actually expects a boolean as the value of even a boolean input parameter in a workflow_dispatch
call is actually a string 'true'
/'false'
.
name: Show inputs
on:
workflow_dispatch:
inputs:
prefersHello:
description: 'Whether the person prefers to greet with a Hello'
required: true
type: boolean
default: false
jobs:
greet_person:
name: Greet the person
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: imaginary/greet@v1
with:
greetWithHello: ${{ github.event.inputs.prefersHello }}
The way to convert this into an actual boolean is to compare the value of the input like this
${{ github.event.inputs.prefersHello == 'true' }}
With that, the previous example turns into:
name: Show inputs
on:
workflow_dispatch:
inputs:
prefersHello:
description: 'Whether the person prefers to greet with a Hello'
required: true
type: boolean
default: false
jobs:
greet_person:
name: Greet the person
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: imaginary/greet@v1
with:
greetWithHello: ${{ github.event.inputs.prefersHello == 'true' }}