diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index 304952f..fae7d71 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -176,6 +176,38 @@ test("getInputAsArray removes spaces after ! at the beginning", () => { ]); }); +test("getInputAsArray handles YAML list format (JSON array)", () => { + testUtils.setInput("foo", '["bar", "baz", "qux"]'); + expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz", "qux"]); +}); + +test("getInputAsArray handles YAML list format with exclusion patterns", () => { + testUtils.setInput( + "foo", + '["~/cache", "! ~/cache/exclude", "**/node_modules"]' + ); + expect(actionUtils.getInputAsArray("foo")).toEqual([ + "~/cache", + "!~/cache/exclude", + "**/node_modules" + ]); +}); + +test("getInputAsArray handles YAML list format with empty strings", () => { + testUtils.setInput("foo", '["bar", "", "baz", " ", "qux"]'); + expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz", "qux"]); +}); + +test("getInputAsArray handles invalid JSON gracefully and falls back to newline parsing", () => { + testUtils.setInput("foo", "[invalid json"); + expect(actionUtils.getInputAsArray("foo")).toEqual(["[invalid json"]); +}); + +test("getInputAsArray handles JSON that is not an array", () => { + testUtils.setInput("foo", '{"key": "value"}'); + expect(actionUtils.getInputAsArray("foo")).toEqual(['{"key": "value"}']); +}); + test("getInputAsInt returns undefined if input not set", () => { expect(actionUtils.getInputAsInt("undefined")).toBeUndefined(); }); diff --git a/dist/restore-only/index.js b/dist/restore-only/index.js index bd24321..3728dc8 100644 --- a/dist/restore-only/index.js +++ b/dist/restore-only/index.js @@ -94969,7 +94969,23 @@ function isValidEvent() { return RefKey in process.env && Boolean(process.env[RefKey]); } function getInputAsArray(name, options) { - return getInput(name, options) + const input = getInput(name, options); + // Try to parse as JSON array (YAML list format) + if (input.startsWith("[")) { + try { + const parsed = JSON.parse(input); + if (Array.isArray(parsed)) { + return parsed + .map(s => String(s).replace(/^!\s+/, "!").trim()) + .filter(x => x !== ""); + } + } + catch { + // Not valid JSON, fall through to newline parsing + } + } + // Fall back to newline-separated format + return input .split("\n") .map(s => s.replace(/^!\s+/, "!").trim()) .filter(x => x !== ""); diff --git a/dist/restore/index.js b/dist/restore/index.js index c7cb184..7679898 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -94969,7 +94969,23 @@ function isValidEvent() { return RefKey in process.env && Boolean(process.env[RefKey]); } function getInputAsArray(name, options) { - return getInput(name, options) + const input = getInput(name, options); + // Try to parse as JSON array (YAML list format) + if (input.startsWith("[")) { + try { + const parsed = JSON.parse(input); + if (Array.isArray(parsed)) { + return parsed + .map(s => String(s).replace(/^!\s+/, "!").trim()) + .filter(x => x !== ""); + } + } + catch { + // Not valid JSON, fall through to newline parsing + } + } + // Fall back to newline-separated format + return input .split("\n") .map(s => s.replace(/^!\s+/, "!").trim()) .filter(x => x !== ""); diff --git a/dist/save-only/index.js b/dist/save-only/index.js index 1b81de3..7a8d980 100644 --- a/dist/save-only/index.js +++ b/dist/save-only/index.js @@ -94974,7 +94974,23 @@ function isValidEvent() { return RefKey in process.env && Boolean(process.env[RefKey]); } function getInputAsArray(name, options) { - return getInput(name, options) + const input = getInput(name, options); + // Try to parse as JSON array (YAML list format) + if (input.startsWith("[")) { + try { + const parsed = JSON.parse(input); + if (Array.isArray(parsed)) { + return parsed + .map(s => String(s).replace(/^!\s+/, "!").trim()) + .filter(x => x !== ""); + } + } + catch { + // Not valid JSON, fall through to newline parsing + } + } + // Fall back to newline-separated format + return input .split("\n") .map(s => s.replace(/^!\s+/, "!").trim()) .filter(x => x !== ""); diff --git a/dist/save/index.js b/dist/save/index.js index 59f6659..d3f249d 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -94974,7 +94974,23 @@ function isValidEvent() { return RefKey in process.env && Boolean(process.env[RefKey]); } function getInputAsArray(name, options) { - return getInput(name, options) + const input = getInput(name, options); + // Try to parse as JSON array (YAML list format) + if (input.startsWith("[")) { + try { + const parsed = JSON.parse(input); + if (Array.isArray(parsed)) { + return parsed + .map(s => String(s).replace(/^!\s+/, "!").trim()) + .filter(x => x !== ""); + } + } + catch { + // Not valid JSON, fall through to newline parsing + } + } + // Fall back to newline-separated format + return input .split("\n") .map(s => s.replace(/^!\s+/, "!").trim()) .filter(x => x !== ""); diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index 260d4fd..3f4a69f 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -40,8 +40,24 @@ export function getInputAsArray( name: string, options?: core.InputOptions ): string[] { - return core - .getInput(name, options) + const input = core.getInput(name, options); + + // Try to parse as JSON array (YAML list format) + if (input.startsWith("[")) { + try { + const parsed = JSON.parse(input); + if (Array.isArray(parsed)) { + return parsed + .map(s => String(s).replace(/^!\s+/, "!").trim()) + .filter(x => x !== ""); + } + } catch { + // Not valid JSON, fall through to newline parsing + } + } + + // Fall back to newline-separated format + return input .split("\n") .map(s => s.replace(/^!\s+/, "!").trim()) .filter(x => x !== "");