I’m trying to create a few choices as input to a GitHub Actions workflow. I’d like the later choices to be prescribed by previous choices. Like this:
name: Test GitHub Workflow Options
on:
workflow_dispatch:
inputs:
letter:
description: 'Letter Choice'
required: true
type: choice
options:
- "A"
- "B"
number:
description: 'Number Choice'
required: true
type: choice
- if: "${{ inputs.letter }}" == "A"
options:
- "1"
- "2"
- if: "${{ inputs.letter }}" == "B"
options:
- "3"
- "4"
Obviously this syntax is incorrect and doesn’t work (I’ve tried different indenting), but is there a way for the first input choice to define the options for the next one, etc.?
Ducati Scotty is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Workflow_dispatch event can be triggered in two ways:
- Via GitHub UI “Run workflow” which presents UI input fields defined under inputs in the workflow. See here for details.
- Via GitHub API – see here
The UI is very likely using the API to create the event.
Due to the nature of the REST API, conditional inputs can not be supported.
In your case the inputs are fixed and required. The set of valid values for number is determined by the selection for letter. Why not set the valid values for number as
A:1, A:2, B:3, B:4. Alternatively you could have several number inputs: numberA, numberB with valid choices and annotate them in the UI with a description.
An alternative that you may want to look into is GitHub environments deployment protection rules. They allow manual approval of workflow jobs with user input. You could create a chain of jobs that refer to different environments that allow different inputs. This is not as elegant as what you proposed but it may give you some approximation of what you want.