github-actions

GithubActions only supports one input type


Today, I struggled to pass an input variable that is not of type String to a GithubAction. Following the constraints of the yaml file-format, I passed a boolean, a String and a List<String>.

inputs:
  boolean_value:
    required: false
  string_value:
    required: false
  list_of_strings:
    required: false
jobs:
  job_name:
    runs-on: ubuntu-latest
    env:
      ENV_VAR1: Hello
      ENV_VAR1: World
    steps:
    - uses: action-name
      with:
        my_boolean: true
        string_value: "someValue"
        list_of_strings: [ $ENV_VAR1, $ENV_VAR2 ]

Processing the inputs, I couldn't access elements of the list and the variables didn't get dereferenced.


Solution

  • GithubActions uses a shell under the hood to handle those variables so everything is converted to a String -> processing the input Array/List doesn't work directly. The most straightforward way I found was using this jQuery:

    for i in $(jq -r '.[]' <<< '${{ list_of_strings }}'); do

    Passing variables into a List of Strings (so a String concatenation to be precise) should look like that:

    list_of_strings: '[ "${{ ENV_VAR1 }}" , "${{ ENV_VAR2 }}" ]'