GitHub Action inputs and array values

In GitHub Actions there are many places where we can use arrays.

For example, when using the matrix strategy:

jobs:
    example_matrix:
        strategy:
            matrix:
                version: [10, 12, 14]

Or when we want to filter whats triggers the workflow:

on:
    push:
        branches:
            - main
            - 'releases/**'

But, we are limited to using only strings, numbers, and booleans for input values.

The following are not valid options according to the spec:

- uses: 'example-action@v1'
    with:
        keys: ['foo', 'bar']
- uses: 'example-action@v1'
    with:
        keys:
            - foo
            - bar

We can use multiline strings if we want something close to multiline values.

- uses: 'example-action@v1'
    with:
        keys: |-
            foo
            bar

But the value of keys is still a string; it only contains new lines.

We have to turn it intro a proper array.

If we use JavaScript actions, it will look something similar:

import core from "@actions/core";

const keys = core.getInput("keys")
    .split(/[\r\n]/)
    .map(input => input.trim())
    .filter(input => input !== '');

It's an important but small detail that we used |- in the YAML and not |.

We can control how we treat the final line break in multiline strings.

Chomping controls how final line breaks and trailing empty lines are interpreted.

For comparison, here's the YAML converted into JSON:

strip: |-
    foo
clip: |
    bar
{
    "strip": "foo",
    "clip": "bar\n"
}