Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sarpik/get input list support #829

Merged
merged 6 commits into from Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/README.md
Expand Up @@ -23,6 +23,7 @@ Outputs can be set with `setOutput` which makes them available to be mapped into
```js
const myInput = core.getInput('inputName', { required: true });
const myBooleanInput = core.getBooleanInput('booleanInputName', { required: true });
const myMultilineInput = core.getMultiline('multilineInputName', { required: true });
core.setOutput('outputKey', 'outputVal');
```

Expand Down
10 changes: 10 additions & 0 deletions packages/core/__tests__/core.test.ts
Expand Up @@ -29,6 +29,8 @@ const testEnvVars = {
INPUT_WRONG_BOOLEAN_INPUT: 'wrong',
INPUT_WITH_TRAILING_WHITESPACE: ' some val ',

INPUT_MY_INPUT_LIST: 'val1\nval2\nval3',

// Save inputs
STATE_TEST_1: 'state_val',

Expand Down Expand Up @@ -166,6 +168,14 @@ describe('@actions/core', () => {
)
})

it('getMultilineInput works', () => {
expect(core.getMultilineInput('my input list')).toEqual([
'val1',
'val2',
'val3'
])
})

it('getInput trims whitespace by default', () => {
expect(core.getInput('with trailing whitespace')).toBe('some val')
})
Expand Down
19 changes: 19 additions & 0 deletions packages/core/src/core.ts
Expand Up @@ -100,6 +100,25 @@ export function getInput(name: string, options?: InputOptions): string {
return val.trim()
}

/**
* Gets the values of an multiline input. Each value is also trimmed.
*
* @param name name of the input to get
* @param options optional. See InputOptions.
* @returns string[]
*
*/
export function getMultilineInput(
name: string,
options?: InputOptions
): string[] {
const inputs: string[] = getInput(name, options)
.split('\n')
thboop marked this conversation as resolved.
Show resolved Hide resolved
.filter(x => x !== '')

return inputs
}

/**
* Gets the input value of the boolean type in the YAML 1.2 "core schema" specification.
* Support boolean input list: `true | True | TRUE | false | False | FALSE` .
Expand Down