Can workflow_dispatch input be option list?

@cschleiden :ok_hand:. This is wonderful feature with options list. I have used this straight away and has made the difference. Can this be multiselect by any chance?

3 Likes

Wouldn’t a list of boolean options (multiple checkboxes) accomplish the same? Or do you refer to the branch/environment dropdown menu?

+1 for dynamic list requirements and thank you for adding this feature

3 Likes

+1 - it’s really important

+1 would be a great addition.

+1 that would be super helpful indeed, expecially if the content can also be dynamic such as fetch the list of tags, branches, or running any shell command that returns a list

+1 this would be a great feature

This has been implemented see type: choice in this article GitHub Actions: Input types for manual workflows | GitHub Changelog

The last line of the GitHub Changelog page for the GitHub Actions Input types shows what appears to be a conditional output of the fromJSON() function where the condition is specified within square braces immediately after the function closing parenthesis…

${{ fromJSON('["", "🥳"]')[github.event.inputs.use-emoji == 'true'] }}

I’m trying to use this syntax in an environment variable definition, but I’m having difficulty and haven’t found any documentation explaining this conditional syntax and where it applies. Can anyone point me in the right direction with this?

on:
  workflow_dispatch:
    inputs:
      testsToInclude1:
        description: "1st set of Tests to include"
        required: true
        default: "smoke-test"
        type: choice
        options:
          - smoke-test
          - regression-test
          - authentication
          - administration
          - auditing
          - call-details
          - call-list
          - calls
          - comment-management
          - comments
          - continuous-monitoring
          - dashboard
          - call-activity
          - phone-activity
          - known-unknowns
          - lexicons
      testsToInclude2:
        description: "2nd set of Tests to include"
        required: false
        default: "none"
        type: choice
        options:
          - none
          - smoke-test
          - regression-test
          - authentication
          - administration
          - auditing
          - call-details
          - call-list
          - calls
          - comment-management
          - comments
          - continuous-monitoring
          - dashboard
          - call-activity
          - phone-activity
          - known-unknowns
          - lexicons
env:
  TESTS_TO_INCLUDE_1: ${{ github.event.inputs.testsToInclude1 }}
  TESTS_TO_INCLUDE_2: ${{ format('{0}', github.event.inputs.testsToInclude2)[github.event.inputs.testsToInclude2 != 'none'] }}

I’m doing this because attempts to set the second choice default to empty string results in the first list option being selected and making the first list option an empty entry results in a 400 error on submit. The above syntax results in the 2nd env var being empty regardless of what value is selected in the choice input.

Also +1 for a dynamic option list mechanism and +1 for a multi-select input type! If I had a multi-select input, I could get away with a single input field here.

It’s not an official syntax for conditions by any means, it’s a hack called a pseudo-ternary operator (also see Do expressions support ternary operators to change their returned value? - #4 by Simran-B). Array literals aren’t supported, but you can construct an array from a JSON string, and then implicitly coerce an expression from a boolean to a number to pick element 0 or 1 based on the evaluation result (false or true). Another technique is to use a logical AND and an OR to do something similar, but with the restriction that the value after && must not be falsy (also see Do expressions support ternary operators to change their returned value? - #3 by Simran-B).

If the input value is not none, then use the specified value, otherwise an empty string:

${{ github.event.inputs.testsToInclude2 != 'none' && github.event.inputs.testsToInclude2 || '' }}

Create an array with the input value and an empty string as members, then pick the latter if the value is none (true => 1) or the former otherwise (false => 0):

${{ fromJSON(format('["{0}",""]', github.event.inputs.testsToInclude2))[github.event.inputs.testsToInclude2 == 'none'] }}


The choice input type doesn’t account for an empty string as an option, which seems like an oversight. I would expect required: false with either no default or default: '' to make no selection a possibility in the UI, but also in the API. Calling the REST endpoint without the testsToInclude2 input or setting it to an empty strings throws an error:

Provided value ‘’ for input ‘testsToInclude2’ not in the list of allowed values

Passing a JSON null value reveals that a JSON Schema is used internally:

Invalid request. For ‘additionalProperties’, nil is not a string.

AFAIK, a JSON Schema can define the allowed values using an enum and it supports an empty string, thus it would be possible on a technical level. The UI would need to add a placeholder entry to the list, either blank or with a label like “Select an option” without passing it on to the API.

2 Likes

Thank you Simran for this very detailed & helpful response!

I agree that choice not accounting for an empty string option seems like an oversight. How can we raise that as a bug or change request to the GitHub Actions team?

You should create a discussion in the feedback repo: https://github.com/github/feedback/discussions/new

2 Likes