diff --git a/lib/run.js b/lib/run.js index b786b7e..e2554b2 100644 --- a/lib/run.js +++ b/lib/run.js @@ -113,9 +113,10 @@ function downloadHelm(version) { }); } exports.downloadHelm = downloadHelm; +// getLatestHelmVersion uses cURL and regex to scrape the latest version function getLatestHelmVersion() { return __awaiter(this, void 0, void 0, function* () { - const command = `curl -Ls https://api.github.com/repos/helm/helm/releases | grep 'v3.[0-9]*.[0-9]*' | sed -E 's/ .*\/helm\/helm\/releases\/tag\/tag\/(v[0-9\.]+)".*/\\1/g' | head -1 | sed -E 's/.*tag\///' | sed -E 's/".*//'`; + const command = `curl -Ls ${helmAllReleasesUrl} | grep 'v3.[0-9]*.[0-9]*' | sed -E 's/ .*\/helm\/helm\/releases\/tag\/tag\/(v[0-9\.]+)".*/\\1/g' | head -1 | sed -E 's/.*tag\///' | sed -E 's/".*//'`; let latestHelm = ""; let latestHelmErr = ""; const options = {}; @@ -128,15 +129,13 @@ function getLatestHelmVersion() { } }; yield exec.exec(command, [], options); - if (latestHelmErr !== "") + if (latestHelmErr !== "" || isValidVersion(latestHelm)) return getStableHelmVersion(); return latestHelm; }); } // isValidVersion checks if verison matches the specified type and is a stable release -function isValidVersion(version, type) { - if (!version.toLocaleLowerCase().startsWith(type)) - return false; +function isValidVersion(version) { return version.indexOf('rc') == -1; } function findHelm(rootFolder) { diff --git a/src/run.ts b/src/run.ts index bfea31f..8651a99 100644 --- a/src/run.ts +++ b/src/run.ts @@ -105,8 +105,9 @@ export async function downloadHelm(version: string): Promise { return helmpath; } +// getLatestHelmVersion uses cURL and regex to scrape the latest version async function getLatestHelmVersion(): Promise{ - const command:string = `curl -Ls https://api.github.com/repos/helm/helm/releases | grep 'v3.[0-9]*.[0-9]*' | sed -E 's/ .*\/helm\/helm\/releases\/tag\/tag\/(v[0-9\.]+)".*/\\1/g' | head -1 | sed -E 's/.*tag\///' | sed -E 's/".*//'`; + const command:string = `curl -Ls ${helmAllReleasesUrl} | grep 'v3.[0-9]*.[0-9]*' | sed -E 's/ .*\/helm\/helm\/releases\/tag\/tag\/(v[0-9\.]+)".*/\\1/g' | head -1 | sed -E 's/.*tag\///' | sed -E 's/".*//'`; let latestHelm: string = ""; let latestHelmErr: string = ""; @@ -123,14 +124,12 @@ async function getLatestHelmVersion(): Promise{ await exec.exec(command, [], options); - if(latestHelmErr !== "") return getStableHelmVersion(); + if(latestHelmErr !== "" || isValidVersion(latestHelm)) return getStableHelmVersion(); return latestHelm; } // isValidVersion checks if verison matches the specified type and is a stable release -function isValidVersion(version: string, type: string): boolean { - if (!version.toLocaleLowerCase().startsWith(type)) - return false; +function isValidVersion(version: string): boolean { return version.indexOf('rc') == -1; }