Skip to content

Commit bb2f393

Browse files
thboopkiprasmel
andauthored
Sarpik/get input list support (#829)
* feat(core): Create `getInputList` utility Signed-off-by: Kipras Melnikovas <kipras@kipras.org> * chore(core): Document usage of '\n' instead of [] @ `getInputList` Signed-off-by: Kipras Melnikovas <kipras@kipras.org> * test(core): Create a very simple test for `getInputList` Signed-off-by: Kipras Melnikovas <kipras@kipras.org> * run linter * update commands/readme Co-authored-by: Kipras Melnikovas <kipras@kipras.org>
1 parent dc4b4da commit bb2f393

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

packages/core/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Outputs can be set with `setOutput` which makes them available to be mapped into
2323
```js
2424
const myInput = core.getInput('inputName', { required: true });
2525
const myBooleanInput = core.getBooleanInput('booleanInputName', { required: true });
26+
const myMultilineInput = core.getMultiline('multilineInputName', { required: true });
2627
core.setOutput('outputKey', 'outputVal');
2728
```
2829

packages/core/__tests__/core.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const testEnvVars = {
2929
INPUT_WRONG_BOOLEAN_INPUT: 'wrong',
3030
INPUT_WITH_TRAILING_WHITESPACE: ' some val ',
3131

32+
INPUT_MY_INPUT_LIST: 'val1\nval2\nval3',
33+
3234
// Save inputs
3335
STATE_TEST_1: 'state_val',
3436

@@ -166,6 +168,14 @@ describe('@actions/core', () => {
166168
)
167169
})
168170

171+
it('getMultilineInput works', () => {
172+
expect(core.getMultilineInput('my input list')).toEqual([
173+
'val1',
174+
'val2',
175+
'val3'
176+
])
177+
})
178+
169179
it('getInput trims whitespace by default', () => {
170180
expect(core.getInput('with trailing whitespace')).toBe('some val')
171181
})

packages/core/src/core.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ export function getInput(name: string, options?: InputOptions): string {
100100
return val.trim()
101101
}
102102

103+
/**
104+
* Gets the values of an multiline input. Each value is also trimmed.
105+
*
106+
* @param name name of the input to get
107+
* @param options optional. See InputOptions.
108+
* @returns string[]
109+
*
110+
*/
111+
export function getMultilineInput(
112+
name: string,
113+
options?: InputOptions
114+
): string[] {
115+
const inputs: string[] = getInput(name, options)
116+
.split('\n')
117+
.filter(x => x !== '')
118+
119+
return inputs
120+
}
121+
103122
/**
104123
* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
105124
* Support boolean input list: `true | True | TRUE | false | False | FALSE` .

0 commit comments

Comments
 (0)