githubgithub-actions

Can you use an `enum` with an input in GitHub Action's `action.yml` and a workflow file?


I have a GitHub action (in .github/actions/my-custom-action) that takes an input which is an enum. In action.yml:

inputs:
  my-enum-input:
    description: "This is an input that's an enum"
    default: "all"
    required: true

Where INPUT_MY_ENUM_INPUT has a type like ['all', 'a', 'b'] that's checked in the script file called by the action.yml file. Is there a way to enforce the enum in the action.yml file as an input, and check the Worksheet YAML file that calls the action to make sure it's valid?


Solution

  • It looks like a lot of people wanted this feature and the GitHub team added it. It is documented in their Workflow syntax for GitHub Actions docs and their blog post announcing the feature. If you declare an input variable name of type choice you can limit the list of input options as shown below:

    inputs:
      name:
        type: choice
        description: Who to greet
        options: 
        - monalisa
        - cschleiden