From 204fa1ab69e643b91bf310c47cbc10fa2843d7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sat, 28 Nov 2020 20:34:06 +0100 Subject: [PATCH 1/4] Sort inputs and remove whitespaces after exclamation at the beginning of lines --- __tests__/actionUtils.test.ts | 30 ++++++++++++++++++++++++++++++ __tests__/restore.test.ts | 2 +- src/utils/actionUtils.ts | 5 +++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index e36a6a5..ae4089f 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -215,6 +215,36 @@ test("getInputAsArray handles empty lines correctly", () => { expect(actionUtils.getInputAsArray("foo")).toEqual(["bar", "baz"]); }); +test("getInputAsArray sorts files correctly", () => { + testUtils.setInput("foo", "bar\n!baz\nwaldo\nqux\nquux\ncorge\ngrault\ngarply"); + expect(actionUtils.getInputAsArray("foo")).toEqual([ + "!baz", + "bar", + "corge", + "garply", + "grault", + "quux", + "qux", + "waldo" + ]); +}); + +test("getInputAsArray removes spaces after ! at the beginning", () => { + testUtils.setInput( + "foo", + "! bar\n! baz\n! qux\n!quux\ncorge\ngrault! garply\n!\r\t waldo" + ); + expect(actionUtils.getInputAsArray("foo")).toEqual([ + "!bar", + "!baz", + "!quux", + "!qux", + "!waldo", + "corge", + "grault! garply" + ]); +}); + test("getInputAsInt returns undefined if input not set", () => { expect(actionUtils.getInputAsInt("undefined")).toBeUndefined(); }); diff --git a/__tests__/restore.test.ts b/__tests__/restore.test.ts index e9a505b..6c02082 100644 --- a/__tests__/restore.test.ts +++ b/__tests__/restore.test.ts @@ -147,7 +147,7 @@ test("restore with no key", async () => { test("restore with too many keys should fail", async () => { const path = "node_modules"; const key = "node-test"; - const restoreKeys = [...Array(20).keys()].map(x => x.toString()); + const restoreKeys = [...Array(20).keys()].map(x => x.toString()).sort(); testUtils.setInputs({ path: path, key, diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index 69e0220..5301bef 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -61,8 +61,9 @@ export function getInputAsArray( return core .getInput(name, options) .split("\n") - .map(s => s.trim()) - .filter(x => x !== ""); + .map(s => s.replace(/^\!\s+/, '!').trim()) + .filter(x => x !== "") + .sort(); } export function getInputAsInt( From f316f94f312df2c754a18dc69959316ae47ef6a2 Mon Sep 17 00:00:00 2001 From: Vipul Date: Mon, 22 Aug 2022 12:45:18 +0000 Subject: [PATCH 2/4] Generate build and fix format --- __tests__/actionUtils.test.ts | 5 ++++- dist/restore/index.js | 5 +++-- dist/save/index.js | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/__tests__/actionUtils.test.ts b/__tests__/actionUtils.test.ts index ae4089f..19425f5 100644 --- a/__tests__/actionUtils.test.ts +++ b/__tests__/actionUtils.test.ts @@ -216,7 +216,10 @@ test("getInputAsArray handles empty lines correctly", () => { }); test("getInputAsArray sorts files correctly", () => { - testUtils.setInput("foo", "bar\n!baz\nwaldo\nqux\nquux\ncorge\ngrault\ngarply"); + testUtils.setInput( + "foo", + "bar\n!baz\nwaldo\nqux\nquux\ncorge\ngrault\ngarply" + ); expect(actionUtils.getInputAsArray("foo")).toEqual([ "!baz", "bar", diff --git a/dist/restore/index.js b/dist/restore/index.js index b4b9aa8..9b10374 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -37662,8 +37662,9 @@ function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") - .map(s => s.trim()) - .filter(x => x !== ""); + .map(s => s.replace(/^\!\s+/, '!').trim()) + .filter(x => x !== "") + .sort(); } exports.getInputAsArray = getInputAsArray; function getInputAsInt(name, options) { diff --git a/dist/save/index.js b/dist/save/index.js index 80b8752..858d68c 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -37662,8 +37662,9 @@ function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") - .map(s => s.trim()) - .filter(x => x !== ""); + .map(s => s.replace(/^\!\s+/, '!').trim()) + .filter(x => x !== "") + .sort(); } exports.getInputAsArray = getInputAsArray; function getInputAsInt(name, options) { From 0ae681867531e1dfbccfa23b9be8c84e4c2ec7b2 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 22 Aug 2022 12:57:35 +0000 Subject: [PATCH 3/4] Formatted files with prettier --- dist/restore/index.js | 2 +- dist/save/index.js | 2 +- src/utils/actionUtils.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 9b10374..51eb439 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -37662,7 +37662,7 @@ function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") - .map(s => s.replace(/^\!\s+/, '!').trim()) + .map(s => s.replace(/^\!\s+/, "!").trim()) .filter(x => x !== "") .sort(); } diff --git a/dist/save/index.js b/dist/save/index.js index 858d68c..cb05442 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -37662,7 +37662,7 @@ function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") - .map(s => s.replace(/^\!\s+/, '!').trim()) + .map(s => s.replace(/^\!\s+/, "!").trim()) .filter(x => x !== "") .sort(); } diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index 5301bef..2f54c3b 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -61,7 +61,7 @@ export function getInputAsArray( return core .getInput(name, options) .split("\n") - .map(s => s.replace(/^\!\s+/, '!').trim()) + .map(s => s.replace(/^\!\s+/, "!").trim()) .filter(x => x !== "") .sort(); } From 8954b0745817a5cd787e58a682ccc504b3c8d37a Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 22 Aug 2022 13:05:20 +0000 Subject: [PATCH 4/4] Removed unnecessary backslash in regex --- dist/restore/index.js | 2 +- dist/save/index.js | 2 +- src/utils/actionUtils.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 51eb439..c79eb6b 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -37662,7 +37662,7 @@ function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") - .map(s => s.replace(/^\!\s+/, "!").trim()) + .map(s => s.replace(/^!\s+/, "!").trim()) .filter(x => x !== "") .sort(); } diff --git a/dist/save/index.js b/dist/save/index.js index cb05442..88ff962 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -37662,7 +37662,7 @@ function getInputAsArray(name, options) { return core .getInput(name, options) .split("\n") - .map(s => s.replace(/^\!\s+/, "!").trim()) + .map(s => s.replace(/^!\s+/, "!").trim()) .filter(x => x !== "") .sort(); } diff --git a/src/utils/actionUtils.ts b/src/utils/actionUtils.ts index 2f54c3b..46c5ec1 100644 --- a/src/utils/actionUtils.ts +++ b/src/utils/actionUtils.ts @@ -61,7 +61,7 @@ export function getInputAsArray( return core .getInput(name, options) .split("\n") - .map(s => s.replace(/^\!\s+/, "!").trim()) + .map(s => s.replace(/^!\s+/, "!").trim()) .filter(x => x !== "") .sort(); }