From c3ede7d37625313ccab990e3c9a99e2c5f71b4af Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:46:33 -0800 Subject: [PATCH 01/15] Add caching --- lib/setup.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/setup.js b/lib/setup.js index 018ecd9..b6471ed 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -122,13 +122,20 @@ async function installUsingNativeInstaller(version) { return ""; } + const cachedPath = tc.find("sam", version); + if (cachedPath) { + core.info(`Using cached AWS SAM CLI from ${cachedPath}`); + return path.join(cachedPath, "dist") + } + const url = version ? `https://github.com/aws/aws-sam-cli/releases/download/v${version}/aws-sam-cli-linux-x86_64.zip` : "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip"; const toolPath = await tc.downloadTool(url); const extractedDir = await tc.extractZip(toolPath); - const binDir = path.join(extractedDir, "dist"); + const cachedDir = await tc.cacheDir(extractedDir, "sam", version); + const binDir = path.join(cachedDir, "dist"); return binDir; } From 2c041ff218020b6abf5c2aaa2e6a6e9959e72396 Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:47:52 -0800 Subject: [PATCH 02/15] Add test --- .github/workflows/test.yml | 7 +++++++ dist/index.js | 9 ++++++++- lib/setup.js | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cbd3ddd..e94d53d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,13 @@ jobs: version: "1.71.0" - run: sam --version | grep -F 1.71.0 + - name: Test official installer (pinned version; should use cache) + uses: ./ + with: + use-installer: true + version: "1.71.0" + - run: sam --version | grep -F 1.71.0 + - name: Test official installer (latest version) uses: ./ with: diff --git a/dist/index.js b/dist/index.js index 1bb769f..fede5dc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -147,13 +147,20 @@ async function installUsingNativeInstaller(version) { return ""; } + const cachedPath = tc.find("sam", version); + if (cachedPath) { + core.info(`Using cached AWS SAM CLI from ${cachedPath}`); + return path.join(cachedPath, "dist"); + } + const url = version ? `https://github.com/aws/aws-sam-cli/releases/download/v${version}/aws-sam-cli-linux-x86_64.zip` : "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip"; const toolPath = await tc.downloadTool(url); const extractedDir = await tc.extractZip(toolPath); - const binDir = path.join(extractedDir, "dist"); + const cachedDir = await tc.cacheDir(extractedDir, "sam", version); + const binDir = path.join(cachedDir, "dist"); return binDir; } diff --git a/lib/setup.js b/lib/setup.js index b6471ed..aa0e2ca 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -125,7 +125,7 @@ async function installUsingNativeInstaller(version) { const cachedPath = tc.find("sam", version); if (cachedPath) { core.info(`Using cached AWS SAM CLI from ${cachedPath}`); - return path.join(cachedPath, "dist") + return path.join(cachedPath, "dist"); } const url = version From 2d99d9ff0c7b88f9e23a4966044c8ea6be51b2cd Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:50:17 -0800 Subject: [PATCH 03/15] Cache if version set --- dist/index.js | 10 ++++++---- lib/setup.js | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index fede5dc..aaed28f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -147,10 +147,12 @@ async function installUsingNativeInstaller(version) { return ""; } - const cachedPath = tc.find("sam", version); - if (cachedPath) { - core.info(`Using cached AWS SAM CLI from ${cachedPath}`); - return path.join(cachedPath, "dist"); + if (version) { + const cachedPath = tc.find("sam", version); + if (cachedPath) { + core.info(`Using cached AWS SAM CLI from ${cachedPath}`); + return path.join(cachedPath, "dist"); + } } const url = version diff --git a/lib/setup.js b/lib/setup.js index aa0e2ca..57f2b0c 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -122,10 +122,12 @@ async function installUsingNativeInstaller(version) { return ""; } - const cachedPath = tc.find("sam", version); - if (cachedPath) { - core.info(`Using cached AWS SAM CLI from ${cachedPath}`); - return path.join(cachedPath, "dist"); + if (version) { + const cachedPath = tc.find("sam", version); + if (cachedPath) { + core.info(`Using cached AWS SAM CLI from ${cachedPath}`); + return path.join(cachedPath, "dist"); + } } const url = version From 0c61f1285daa4e4f4ad4535850e30de706c963bf Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:53:20 -0800 Subject: [PATCH 04/15] Remove TODO --- lib/setup.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/setup.js b/lib/setup.js index 57f2b0c..3eb82b4 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -115,7 +115,6 @@ function getInput(name, pattern, defaultValue) { * @returns {Promise} The directory SAM CLI is installed in. */ // TODO: Support more platforms -// TODO: Support caching async function installUsingNativeInstaller(version) { if (os.platform() !== "linux" || os.arch() !== "x64") { core.setFailed("Only Linux x86-64 is supported with use-installer: true"); From 5f91a1cf8ae281db8f5f1d4eb5efcbd14f505fed Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:53:54 -0800 Subject: [PATCH 05/15] npm run all --- dist/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index aaed28f..e0ab4f2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -140,7 +140,6 @@ function getInput(name, pattern, defaultValue) { * @returns {Promise} The directory SAM CLI is installed in. */ // TODO: Support more platforms -// TODO: Support caching async function installUsingNativeInstaller(version) { if (os.platform() !== "linux" || os.arch() !== "x64") { core.setFailed("Only Linux x86-64 is supported with use-installer: true"); From e0e9cc480ff3292a490f780a62e6cdc597afb93e Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 19:07:25 -0800 Subject: [PATCH 06/15] Refactor --- dist/index.js | 8 ++++---- lib/setup.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index e0ab4f2..03dbeae 100644 --- a/dist/index.js +++ b/dist/index.js @@ -147,10 +147,10 @@ async function installUsingNativeInstaller(version) { } if (version) { - const cachedPath = tc.find("sam", version); - if (cachedPath) { - core.info(`Using cached AWS SAM CLI from ${cachedPath}`); - return path.join(cachedPath, "dist"); + const cachedDir = tc.find("sam", version); + if (cachedDir) { + core.info(`Using cached AWS SAM CLI from ${cachedDir}`); + return path.join(cachedDir, "dist"); } } diff --git a/lib/setup.js b/lib/setup.js index 3eb82b4..81119b1 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -122,10 +122,10 @@ async function installUsingNativeInstaller(version) { } if (version) { - const cachedPath = tc.find("sam", version); - if (cachedPath) { - core.info(`Using cached AWS SAM CLI from ${cachedPath}`); - return path.join(cachedPath, "dist"); + const cachedDir = tc.find("sam", version); + if (cachedDir) { + core.info(`Using cached AWS SAM CLI from ${cachedDir}`); + return path.join(cachedDir, "dist"); } } From 7b3183891ef5bffdec7ae46863f549771c2047e2 Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 19:21:02 -0800 Subject: [PATCH 07/15] Improve log --- lib/setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/setup.js b/lib/setup.js index 81119b1..233c7ae 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -124,7 +124,7 @@ async function installUsingNativeInstaller(version) { if (version) { const cachedDir = tc.find("sam", version); if (cachedDir) { - core.info(`Using cached AWS SAM CLI from ${cachedDir}`); + core.info(`Using cached AWS SAM CLI ${version} from ${cachedDir}`); return path.join(cachedDir, "dist"); } } From 2f57a271d72243790be6f5c54e23ace6e9af46bf Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 19:31:09 -0800 Subject: [PATCH 08/15] Only cache if version set --- dist/index.js | 10 +++++++--- lib/setup.js | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 03dbeae..6581136 100644 --- a/dist/index.js +++ b/dist/index.js @@ -149,7 +149,7 @@ async function installUsingNativeInstaller(version) { if (version) { const cachedDir = tc.find("sam", version); if (cachedDir) { - core.info(`Using cached AWS SAM CLI from ${cachedDir}`); + core.info(`Using cached AWS SAM CLI ${version} from ${cachedDir}`); return path.join(cachedDir, "dist"); } } @@ -160,8 +160,12 @@ async function installUsingNativeInstaller(version) { const toolPath = await tc.downloadTool(url); const extractedDir = await tc.extractZip(toolPath); - const cachedDir = await tc.cacheDir(extractedDir, "sam", version); - const binDir = path.join(cachedDir, "dist"); + const binDir = path.join(extractedDir, "dist"); + + if (version) { + const cachedDir = await tc.cacheDir(extractedDir, "sam", version); + core.info(`Cached AWS SAM CLI ${version} to ${cachedDir}`); + } return binDir; } diff --git a/lib/setup.js b/lib/setup.js index 233c7ae..9a58412 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -135,8 +135,12 @@ async function installUsingNativeInstaller(version) { const toolPath = await tc.downloadTool(url); const extractedDir = await tc.extractZip(toolPath); - const cachedDir = await tc.cacheDir(extractedDir, "sam", version); - const binDir = path.join(cachedDir, "dist"); + const binDir = path.join(extractedDir, "dist"); + + if (version) { + const cachedDir = await tc.cacheDir(extractedDir, "sam", version); + core.info(`Cached AWS SAM CLI ${version} to ${cachedDir}`); + } return binDir; } From fb193b2544def1f7211f310a3a63660f57cf1e5c Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 19:38:14 -0800 Subject: [PATCH 09/15] Add TODOs --- dist/index.js | 2 ++ lib/setup.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dist/index.js b/dist/index.js index 6581136..c0be62a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -146,6 +146,7 @@ async function installUsingNativeInstaller(version) { return ""; } + // TODO: If not set, check latest version and return from cache if exists if (version) { const cachedDir = tc.find("sam", version); if (cachedDir) { @@ -162,6 +163,7 @@ async function installUsingNativeInstaller(version) { const extractedDir = await tc.extractZip(toolPath); const binDir = path.join(extractedDir, "dist"); + // TODO: If not set, cache with latest version if (version) { const cachedDir = await tc.cacheDir(extractedDir, "sam", version); core.info(`Cached AWS SAM CLI ${version} to ${cachedDir}`); diff --git a/lib/setup.js b/lib/setup.js index 9a58412..3e09069 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -121,6 +121,7 @@ async function installUsingNativeInstaller(version) { return ""; } + // TODO: If not set, check latest version and return from cache if exists if (version) { const cachedDir = tc.find("sam", version); if (cachedDir) { @@ -137,6 +138,7 @@ async function installUsingNativeInstaller(version) { const extractedDir = await tc.extractZip(toolPath); const binDir = path.join(extractedDir, "dist"); + // TODO: If not set, cache with latest version if (version) { const cachedDir = await tc.cacheDir(extractedDir, "sam", version); core.info(`Cached AWS SAM CLI ${version} to ${cachedDir}`); From f6778e349cdd1f6550525df2d4fd87af41e48395 Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Wed, 1 Mar 2023 20:19:25 -0800 Subject: [PATCH 10/15] Add tests --- test/setup.test.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/setup.test.js b/test/setup.test.js index 0073ee8..950b410 100644 --- a/test/setup.test.js +++ b/test/setup.test.js @@ -1,12 +1,14 @@ jest.mock("@actions/core"); jest.mock("@actions/exec"); jest.mock("@actions/io"); +jest.mock("@actions/tool-cache"); const os = require("os"); const core = require("@actions/core"); const exec = require("@actions/exec"); const io = require("@actions/io"); +const tc = require("@actions/tool-cache"); const setup = require("../lib/setup"); @@ -82,3 +84,35 @@ test.each([ .mockReturnValueOnce(input.python); await expect(setup).rejects.toThrow(Error); }); + +test("when use-installer enabled and version specified and cached version exists, uses cached version", async () => { + jest.spyOn(os, "platform").mockReturnValue("linux"); + jest.spyOn(os, "arch").mockReturnValue("x64"); + + core.getBooleanInput = jest.fn().mockReturnValue(true); + core.getInput = jest.fn().mockReturnValueOnce("1.2.3"); + + tc.find = jest.fn().mockReturnValueOnce("/path/to/cached/sam"); + + await setup(); + + expect(tc.find).toHaveBeenCalledTimes(1); + expect(tc.cacheDir).toHaveBeenCalledTimes(0); +}); + +test("when use-installer enabled and version specified and cached version does not exist, downloads and caches version", async () => { + jest.spyOn(os, "platform").mockReturnValue("linux"); + jest.spyOn(os, "arch").mockReturnValue("x64"); + + core.getBooleanInput = jest.fn().mockReturnValue(true); + core.getInput = jest.fn().mockReturnValueOnce("1.2.3"); + + tc.find = jest.fn().mockReturnValueOnce(""); + tc.extractZip = jest.fn().mockReturnValueOnce("/path/to/cached/sam"); + tc.cacheDir = jest.fn().mockReturnValueOnce("/path/to/cached/sam"); + + await setup(); + + expect(tc.find).toHaveBeenCalledTimes(1); + expect(tc.cacheDir).toHaveBeenCalledTimes(1); +}); From aa53c7bf19984c8c38530b6e43831720259f5327 Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:59:52 -0800 Subject: [PATCH 11/15] Return cached dir --- dist/index.js | 1 + lib/setup.js | 1 + test/setup.test.js | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index c0be62a..22757d0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -167,6 +167,7 @@ async function installUsingNativeInstaller(version) { if (version) { const cachedDir = await tc.cacheDir(extractedDir, "sam", version); core.info(`Cached AWS SAM CLI ${version} to ${cachedDir}`); + return path.join(cachedDir, "dist"); } return binDir; diff --git a/lib/setup.js b/lib/setup.js index 3e09069..8986121 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -142,6 +142,7 @@ async function installUsingNativeInstaller(version) { if (version) { const cachedDir = await tc.cacheDir(extractedDir, "sam", version); core.info(`Cached AWS SAM CLI ${version} to ${cachedDir}`); + return path.join(cachedDir, "dist"); } return binDir; diff --git a/test/setup.test.js b/test/setup.test.js index 950b410..04b7f30 100644 --- a/test/setup.test.js +++ b/test/setup.test.js @@ -98,6 +98,9 @@ test("when use-installer enabled and version specified and cached version exists expect(tc.find).toHaveBeenCalledTimes(1); expect(tc.cacheDir).toHaveBeenCalledTimes(0); + + // Must be cached path + expect(core.addPath).toHaveBeenCalledWith("/path/to/cached/sam/dist"); }); test("when use-installer enabled and version specified and cached version does not exist, downloads and caches version", async () => { @@ -108,11 +111,39 @@ test("when use-installer enabled and version specified and cached version does n core.getInput = jest.fn().mockReturnValueOnce("1.2.3"); tc.find = jest.fn().mockReturnValueOnce(""); - tc.extractZip = jest.fn().mockReturnValueOnce("/path/to/cached/sam"); + tc.extractZip = jest.fn().mockReturnValueOnce("/path/to/extracted/sam"); tc.cacheDir = jest.fn().mockReturnValueOnce("/path/to/cached/sam"); await setup(); expect(tc.find).toHaveBeenCalledTimes(1); expect(tc.cacheDir).toHaveBeenCalledTimes(1); + + // Must return cached path + expect(core.addPath).toHaveBeenCalledWith("/path/to/cached/sam/dist"); +}); + +test("when use-installer enabled and version not specified, downloads latest version (Linux x64)", async () => { + jest.spyOn(os, "platform").mockReturnValue("linux"); + jest.spyOn(os, "arch").mockReturnValue("x64"); + + core.getBooleanInput = jest.fn().mockReturnValue(true); + core.getInput = jest.fn().mockReturnValueOnce(""); + + tc.find = jest.fn().mockReturnValueOnce(""); + tc.extractZip = jest.fn().mockReturnValueOnce("/path/to/extracted/sam"); + tc.cacheDir = jest.fn().mockReturnValueOnce("/path/to/cached/sam"); + tc.downloadTool = jest.fn().mockReturnValueOnce("/path/to/downloaded/sam"); + + await setup(); + + // Currently no caching on latest + expect(tc.find).toHaveBeenCalledTimes(0); + expect(tc.cacheDir).toHaveBeenCalledTimes(0); + + expect(tc.downloadTool).toHaveBeenCalledWith( + "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip" + ); + + expect(core.addPath).toHaveBeenCalledWith("/path/to/extracted/sam/dist"); }); From 660bffbe186fdd3decc96b5302a9d298491dea9e Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:07:21 -0800 Subject: [PATCH 12/15] Refactor test --- test/setup.test.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/setup.test.js b/test/setup.test.js index 04b7f30..fe0c7d4 100644 --- a/test/setup.test.js +++ b/test/setup.test.js @@ -137,13 +137,12 @@ test("when use-installer enabled and version not specified, downloads latest ver await setup(); - // Currently no caching on latest - expect(tc.find).toHaveBeenCalledTimes(0); - expect(tc.cacheDir).toHaveBeenCalledTimes(0); - expect(tc.downloadTool).toHaveBeenCalledWith( "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip" ); + // Currently no caching on latest + expect(tc.find).toHaveBeenCalledTimes(0); + expect(tc.cacheDir).toHaveBeenCalledTimes(0); expect(core.addPath).toHaveBeenCalledWith("/path/to/extracted/sam/dist"); }); From 3d2be4134458dabe2f70685670092e4c71f1b830 Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:23:03 -0800 Subject: [PATCH 13/15] More tests --- dist/index.js | 13 +++++++++++++ lib/setup.js | 13 +++++++++++++ test/setup.test.js | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/dist/index.js b/dist/index.js index 22757d0..8c7181a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -131,6 +131,13 @@ function getInput(name, pattern, defaultValue) { return value; } +/** + * Returns whether a string is in the format x.y.z. + */ +function isSemver(s) { + return /^\d.\d.\d$/.test(s); +} + /** * Installs SAM CLI using the native installers. * @@ -146,6 +153,12 @@ async function installUsingNativeInstaller(version) { return ""; } + // Must be full semantic version; downloads version directly from GitHub + if (version && !isSemver(version)) { + core.setFailed("Version must be in the format x.y.z"); + return ""; + } + // TODO: If not set, check latest version and return from cache if exists if (version) { const cachedDir = tc.find("sam", version); diff --git a/lib/setup.js b/lib/setup.js index 8986121..940642c 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -106,6 +106,13 @@ function getInput(name, pattern, defaultValue) { return value; } +/** + * Returns whether a string is in the format x.y.z. + */ +function isSemver(s) { + return /^\d.\d.\d$/.test(s); +} + /** * Installs SAM CLI using the native installers. * @@ -121,6 +128,12 @@ async function installUsingNativeInstaller(version) { return ""; } + // Must be full semantic version; downloads version directly from GitHub + if (version && !isSemver(version)) { + core.setFailed("Version must be in the format x.y.z"); + return ""; + } + // TODO: If not set, check latest version and return from cache if exists if (version) { const cachedDir = tc.find("sam", version); diff --git a/test/setup.test.js b/test/setup.test.js index fe0c7d4..3717a84 100644 --- a/test/setup.test.js +++ b/test/setup.test.js @@ -146,3 +146,16 @@ test("when use-installer enabled and version not specified, downloads latest ver expect(tc.cacheDir).toHaveBeenCalledTimes(0); expect(core.addPath).toHaveBeenCalledWith("/path/to/extracted/sam/dist"); }); + +test("when use-installer enabled but version is either '1.2', '1.2.a', or 'foo', downloadTool is not called", async () => { + jest.spyOn(os, "platform").mockReturnValue("linux"); + jest.spyOn(os, "arch").mockReturnValue("x64"); + + core.getBooleanInput = jest.fn().mockReturnValue(true); + + for (const version of ["1.2", "1.*", "3"]) { + core.getInput = jest.fn().mockReturnValueOnce(version); + await setup(); + expect(tc.downloadTool).toHaveBeenCalledTimes(0); + } +}); From cf24ef51df01f2664ca301aecb00ceb064d28891 Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:24:23 -0800 Subject: [PATCH 14/15] Refactor test --- test/setup.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/setup.test.js b/test/setup.test.js index 3717a84..b724899 100644 --- a/test/setup.test.js +++ b/test/setup.test.js @@ -147,7 +147,7 @@ test("when use-installer enabled and version not specified, downloads latest ver expect(core.addPath).toHaveBeenCalledWith("/path/to/extracted/sam/dist"); }); -test("when use-installer enabled but version is either '1.2', '1.2.a', or 'foo', downloadTool is not called", async () => { +test("when use-installer enabled but version is not in format x.y.z, not downloaded or checked in cache", async () => { jest.spyOn(os, "platform").mockReturnValue("linux"); jest.spyOn(os, "arch").mockReturnValue("x64"); @@ -157,5 +157,6 @@ test("when use-installer enabled but version is either '1.2', '1.2.a', or 'foo', core.getInput = jest.fn().mockReturnValueOnce(version); await setup(); expect(tc.downloadTool).toHaveBeenCalledTimes(0); + expect(tc.find).toHaveBeenCalledTimes(0); } }); From 0d874b934ac055a490a5b475ea67d26d34f8cb3e Mon Sep 17 00:00:00 2001 From: Christoffer Rehn <1280602+hoffa@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:26:58 -0800 Subject: [PATCH 15/15] Fix semver check --- dist/index.js | 2 +- lib/setup.js | 2 +- test/setup.test.js | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8c7181a..d59b1bf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -135,7 +135,7 @@ function getInput(name, pattern, defaultValue) { * Returns whether a string is in the format x.y.z. */ function isSemver(s) { - return /^\d.\d.\d$/.test(s); + return /^\d+\.\d+\.\d+$/.test(s); } /** diff --git a/lib/setup.js b/lib/setup.js index 940642c..f099fdf 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -110,7 +110,7 @@ function getInput(name, pattern, defaultValue) { * Returns whether a string is in the format x.y.z. */ function isSemver(s) { - return /^\d.\d.\d$/.test(s); + return /^\d+\.\d+\.\d+$/.test(s); } /** diff --git a/test/setup.test.js b/test/setup.test.js index b724899..7ecb212 100644 --- a/test/setup.test.js +++ b/test/setup.test.js @@ -90,7 +90,7 @@ test("when use-installer enabled and version specified and cached version exists jest.spyOn(os, "arch").mockReturnValue("x64"); core.getBooleanInput = jest.fn().mockReturnValue(true); - core.getInput = jest.fn().mockReturnValueOnce("1.2.3"); + core.getInput = jest.fn().mockReturnValueOnce("1.23.456"); tc.find = jest.fn().mockReturnValueOnce("/path/to/cached/sam"); @@ -108,7 +108,7 @@ test("when use-installer enabled and version specified and cached version does n jest.spyOn(os, "arch").mockReturnValue("x64"); core.getBooleanInput = jest.fn().mockReturnValue(true); - core.getInput = jest.fn().mockReturnValueOnce("1.2.3"); + core.getInput = jest.fn().mockReturnValueOnce("1.23.456"); tc.find = jest.fn().mockReturnValueOnce(""); tc.extractZip = jest.fn().mockReturnValueOnce("/path/to/extracted/sam");