toolkit
toolkit copied to clipboard
Support list input type
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 you have found a security issue please submit it here
- If you have questions about writing workflows or action files, then please visit the GitHub Community Forum's Actions Board
- If you are having an issue or question about GitHub Actions then please contact customer support
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.
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
Was this fixed with #829?
@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 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.
I'm happy with this workaround posted on StackOverflow:
- Definition: Use a property of type
stringand a literal with the JSON representation of the list, e.g.products: '["yellow", "green"]' - 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) }}
can we have this pwease :3
Any movement on supporting list inputs?
@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