Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/core/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ const testEnvVars = {
INPUT_WRONG_BOOLEAN_INPUT: 'wrong',
INPUT_WITH_TRAILING_WHITESPACE: ' some val ',

// Set input lists
/**
* why `'\n'` instead of an `[]`: https://github.com/actions/cache/issues/44#issuecomment-549399196
* the FR for this feature + tracking of the previous one: https://github.com/actions/toolkit/issues/184
*/
INPUT_MY_INPUT_LIST: 'val1\nval2\nval3',

// Save inputs
STATE_TEST_1: 'state_val',

Expand Down Expand Up @@ -166,6 +173,10 @@ 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
16 changes: 16 additions & 0 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ 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')
.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