Skip to content

Commit

Permalink
feat(core): handle comma seperated lists in getMultilineInput
Browse files Browse the repository at this point in the history
This commit makes sure that the core.getMultilineInput function can also
parse comma-separated lists (i.e. `[val1,val2,val3]` and `val1,val2,val3`).
  • Loading branch information
rickstaa committed Sep 25, 2022
1 parent ebe4ac3 commit d74927b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
21 changes: 21 additions & 0 deletions packages/core/__tests__/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const testEnvVars = {
INPUT_WITH_TRAILING_WHITESPACE: ' some val ',

INPUT_MY_INPUT_LIST: 'val1\nval2\nval3',
INPUT_MY_INPUT_LIST_2: 'val1,val2,val3',
INPUT_MY_INPUT_LIST_3: '[val1,val2,val3]',
INPUT_MY_INPUT_LIST_4: '[val1, val2, val3]',

// Save inputs
STATE_TEST_1: 'state_val',
Expand Down Expand Up @@ -218,6 +221,24 @@ describe('@actions/core', () => {
'val2',
'val3'
])

expect(core.getMultilineInput('my input list 2')).toEqual([
'val1',
'val2',
'val3'
])

expect(core.getMultilineInput('my input list 3')).toEqual([
'val1',
'val2',
'val3'
])

expect(core.getMultilineInput('my input list 4')).toEqual([
'val1',
'val2',
'val3'
])
})

it('getInput trims whitespace by default', () => {
Expand Down
13 changes: 4 additions & 9 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ export function getMultilineInput(
options?: InputOptions
): string[] {
const inputs: string[] = getInput(name, options)
.split('\n')
.split(/[\[\]\n,]+/)
.map(s => s.trim())
.filter(x => x !== '')

return inputs
Expand Down Expand Up @@ -378,14 +379,8 @@ export async function getIDToken(aud?: string): Promise<string> {
/**
* Summary exports
*/
export {summary} from './summary'

/**
* @deprecated use core.summary
*/
export {markdownSummary} from './summary'

/**
* Path exports
*/
export {toPosixPath, toWin32Path, toPlatformPath} from './path-utils'
export {toPlatformPath, toPosixPath, toWin32Path} from './path-utils'
export {markdownSummary, summary} from './summary'

0 comments on commit d74927b

Please sign in to comment.