From 0fb5515db15794072a92f39339b830969586ef8e Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Fri, 7 Feb 2020 00:39:06 +0200 Subject: [PATCH 1/5] feat(core): Create `getInputList` utility Signed-off-by: Kipras Melnikovas --- packages/core/src/core.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index dcaab53e58..5d9294580d 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -74,6 +74,21 @@ export function getInput(name: string, options?: InputOptions): string { return val.trim() } +/** + * Gets the values of an input list. Each value is also trimmed. + * + * @param name name of the input list to get + * @param options optional. See InputOptions. + * @returns string[] + */ +export function getInputList(name: string, options?: InputOptions): string[] { + const inputs: string[] = getInput(name, options) + .split('\n') + .filter(x => x !== '') + + return inputs +} + /** * Sets the value of an output. * From 86a466ba845d15af32987e847d1f86f041caecfe Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Fri, 7 Feb 2020 00:42:24 +0200 Subject: [PATCH 2/5] chore(core): Document usage of '\n' instead of [] @ `getInputList` Signed-off-by: Kipras Melnikovas --- packages/core/src/core.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index 5d9294580d..66435dba05 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -80,6 +80,11 @@ export function getInput(name: string, options?: InputOptions): string { * @param name name of the input list to get * @param options optional. See InputOptions. * @returns string[] + * + * See also: + * + * 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 */ export function getInputList(name: string, options?: InputOptions): string[] { const inputs: string[] = getInput(name, options) From a4e0c5cc8e894a06996d41dfb4af229aabeba0f8 Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Fri, 7 Feb 2020 00:45:42 +0200 Subject: [PATCH 3/5] test(core): Create a very simple test for `getInputList` Signed-off-by: Kipras Melnikovas --- packages/core/__tests__/core.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/core/__tests__/core.test.ts b/packages/core/__tests__/core.test.ts index 90235428e8..247df92ff8 100644 --- a/packages/core/__tests__/core.test.ts +++ b/packages/core/__tests__/core.test.ts @@ -19,6 +19,13 @@ const testEnvVars = { 'INPUT_SPECIAL_CHARS_\'\t"\\': '\'\t"\\ response ', INPUT_MULTIPLE_SPACES_VARIABLE: 'I have multiple spaces', + // 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' } @@ -99,6 +106,10 @@ describe('@actions/core', () => { ) }) + it('getInputList works', () => { + expect(core.getInputList('my input list')).toEqual(['val1', 'val2', 'val3']) + }) + it('setOutput produces the correct command', () => { core.setOutput('some output', 'some value') assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]) From 138665a5ff067acaa58adc3b5cc9cc0c5e916319 Mon Sep 17 00:00:00 2001 From: Thomas Boop Date: Thu, 3 Jun 2021 23:26:43 -0400 Subject: [PATCH 4/5] run linter --- packages/core/__tests__/core.test.ts | 8 ++++++-- packages/core/src/core.ts | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/__tests__/core.test.ts b/packages/core/__tests__/core.test.ts index d186ed30fa..317b1b71f9 100644 --- a/packages/core/__tests__/core.test.ts +++ b/packages/core/__tests__/core.test.ts @@ -174,9 +174,13 @@ describe('@actions/core', () => { }) it('getMultilineInput works', () => { - expect(core.getMultilineInput('my input list')).toEqual(['val1', 'val2', 'val3']) + 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') }) diff --git a/packages/core/src/core.ts b/packages/core/src/core.ts index de1410acd2..c5c36fa4f5 100644 --- a/packages/core/src/core.ts +++ b/packages/core/src/core.ts @@ -108,7 +108,10 @@ export function getInput(name: string, options?: InputOptions): string { * @returns string[] * */ -export function getMultilineInput(name: string, options?: InputOptions): string[] { +export function getMultilineInput( + name: string, + options?: InputOptions +): string[] { const inputs: string[] = getInput(name, options) .split('\n') .filter(x => x !== '') From 3156b656a76ca3fe17442543663a22113c508ace Mon Sep 17 00:00:00 2001 From: Thomas Boop Date: Thu, 3 Jun 2021 23:33:12 -0400 Subject: [PATCH 5/5] update commands/readme --- packages/core/README.md | 1 + packages/core/__tests__/core.test.ts | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/core/README.md b/packages/core/README.md index cbb9cfcc87..56ee5f1eac 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -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'); ``` diff --git a/packages/core/__tests__/core.test.ts b/packages/core/__tests__/core.test.ts index 317b1b71f9..5be8df4e8f 100644 --- a/packages/core/__tests__/core.test.ts +++ b/packages/core/__tests__/core.test.ts @@ -29,11 +29,6 @@ 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