Skip to content

vlukashov/boolean-workflow-input-issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Adding an optional boolean input to a GitHub workflow breaks the /dispatches API clients

The GitHub REST API allows users to create workflow dispatch events programmatically. For example, the test.yaml workflow in this repo can be dispatched with

curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  https://api.github.com/repos/vlukashov/boolean-workflow-input-issue/actions/workflows/test.yaml/dispatches \
  -d '{"ref":"main"}'

The test.yaml workflow has an optional string input name:

inputs:
  name:
    description: An optional string workflow input
    type: string

The /dispatches REST API works regardless of whether or not the name input is provided.

curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  https://api.github.com/repos/vlukashov/boolean-workflow-input-issue/actions/workflows/test.yaml/dispatches \
  -d '{"ref":"main","inputs":{"name":"Mona the Octocat"}}'

The issue: adding an optional boolean workflow input causes these API calls to fail

The with-boolean-input branch of this repo adds an optional boolean input to the test.yaml workflow:

has_admin_role:
  description: An optional boolean workflow input
  type: boolean

With that, the API calls that used to work now fail:

curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  https://api.github.com/repos/vlukashov/boolean-workflow-input-issue/actions/workflows/test.yaml/dispatches \
  -d '{"ref":"with-boolean-input","inputs":{"name":"Mona the Octocat"}}'

{
  "message": "Provided value '' for input 'has_admin_role' not in the list of allowed values",
  "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}

The API call fails in the same way regardless whether or not it includes the inputs parameter at all.

curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  https://api.github.com/repos/vlukashov/boolean-workflow-input-issue/actions/workflows/test.yaml/dispatches \
  -d '{"ref":"with-boolean-input"}'

{
  "message": "Provided value '' for input 'has_admin_role' not in the list of allowed values",
  "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}

Expected behaviour

Adding any optional workflow inputs should not cause working API calls to fail.

Workaround

Do not use the boolean input type. Instead, use the choice type with true and false options, and false as the default value.

About

Demo repo for an issue with boolean inputs to GH workflows

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published