toolkit icon indicating copy to clipboard operation
toolkit copied to clipboard

Support list input type

Open bryanmacfarlane opened this issue 6 years ago • 7 comments

Thank you 🙇‍♀ for wanting to create an issue in this repository. Before you do, please ensure you are filing the issue in the right place. Issues should only be opened on if the issue relates to code in this repository.

If your issue is relevant to this repository, please include the information below:

Describe the enhancement An action should be able to have an input type which is a list of strings. The toolkit should provide a getInput overload or new method to retrieve it.

Code Snippet

let vals: string[] = core.getListInput('inputName');

Additional information Add any other context about the feature here.

bryanmacfarlane avatar Oct 10 '19 01:10 bryanmacfarlane

I was going through https://github.com/actions/cache trying to implement multiple path support, and when going through source code, I only noticed the core.getInput function, but not one for core.getInputs to get multiple of them.

Then, later, I found this:

const restoreKeys = core
	.getInput(Inputs.RestoreKeys)
	.split("\n")
	.filter(x => x !== "");

so, is

let vals: string[] = core.getInput('inputName').split("\n").filter(x => x !== "");

the official way of doing it?

If so, I've created a PR to implement this: https://github.com/actions/toolkit/pull/336

kiprasmel avatar Feb 06 '20 22:02 kiprasmel

Was this fixed with #829?

AB-xdev avatar Aug 31 '21 09:08 AB-xdev

@AB-xdev, as far as I can tell, #829 implements support for values spanning multiple lines, not lists. With the implemented core.getMultilineInput() the following should be possible:

- uses: myaction
  with:
    multiline-param: |
      line1
      line2
      line3

However, the following is still not possible:

- uses: myaction
  with:
    list-param: ['item1', 'item2', 'item3']

Neither is this:

- uses: myaction
  with:
    list-param:
      - item1
      - item2
      - item3

asbjornu avatar Jul 28 '22 21:07 asbjornu

@asbjornu Good extension! I created #1183 to also implement the second case. Not sure how to implement the last case since these parameters are passed as an environment parameter.

rickstaa avatar Sep 25 '22 07:09 rickstaa

I'm happy with this workaround posted on StackOverflow:

  1. Definition: Use a property of type string and a literal with the JSON representation of the list, e.g. products: '["yellow", "green"]'
  2. Use: Decode the string literal to a JSON list, e.g. ${{ fromJSON(inputs.products) }}

Example:

on:
  workflow_dispatch:
    inputs:
      products:
        description: "List of Products"
        default: '["yellow"]'
      limits:
        description: "List of limits"
        default: '[50]'

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        product: ${{ fromJSON(github.event.inputs.products) }}
        limits: ${{ fromJSON(github.event.inputs.limits) }}

git-developer avatar Aug 06 '23 14:08 git-developer

can we have this pwease :3

Edwardius avatar Oct 18 '23 04:10 Edwardius

Any movement on supporting list inputs?

sroomberg-ep avatar Mar 27 '25 16:03 sroomberg-ep

@sroomberg-ep I believe you are looking for getMultilineInput merged from #829

I also have a pull-request which addresses similar feature request, but it has been unreviewed for few months #1926

iamstarkov avatar Apr 09 '25 20:04 iamstarkov