From b3efc63e7e47f084c95668d70ff997cfd63db27e Mon Sep 17 00:00:00 2001 From: Asa Gayle Date: Tue, 8 Feb 2022 11:08:15 -0500 Subject: [PATCH] Added version validation check --- src/run.test.ts | 4 ++++ src/run.ts | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/src/run.test.ts b/src/run.test.ts index d50930d..0dcea78 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -60,6 +60,10 @@ describe("run.ts", () => { expect(os.arch).toBeCalled(); }); + test("getValidVersion() - return version with v prepended", () => { + expect(run.getValidVersion("3.8.0")).toBe("v3.8.0"); + }); + test("getHelmDownloadURL() - return the URL to download helm for Windows", () => { jest.spyOn(os, "type").mockReturnValue("Windows_NT"); diff --git a/src/run.ts b/src/run.ts index 1e58f01..0d6760f 100644 --- a/src/run.ts +++ b/src/run.ts @@ -17,6 +17,9 @@ const helmAllReleasesUrl = "https://api.github.com/repos/helm/helm/releases"; export async function run() { let version = core.getInput("version", { required: true }); + if(version[0] !== "v"){ + version = getValidVersion(version); + } if (version.toLocaleLowerCase() === "latest") { version = await getLatestHelmVersion(); } @@ -38,6 +41,11 @@ export async function run() { core.setOutput("helm-path", cachedPath); } +//Returns version with proper v before it +export function getValidVersion(version:string): string { + return "v" + version; +} + // Downloads the helm releases JSON and parses all the recent versions of helm from it. // Defaults to sending stable helm version if none are valid or if it fails