4
0
Fork 0
mirror of https://github.com/Azure/setup-helm.git synced 2025-11-08 05:26:56 +00:00

Added comment on getLatestHelmVersion and variable for helm release url to command

This commit is contained in:
Asa Gayle 2022-01-14 09:46:29 -05:00
parent e468b13d6c
commit b34dae9d36
2 changed files with 8 additions and 10 deletions

View file

@ -113,9 +113,10 @@ function downloadHelm(version) {
}); });
} }
exports.downloadHelm = downloadHelm; exports.downloadHelm = downloadHelm;
// getLatestHelmVersion uses cURL and regex to scrape the latest version
function getLatestHelmVersion() { function getLatestHelmVersion() {
return __awaiter(this, void 0, void 0, function* () { 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 latestHelm = "";
let latestHelmErr = ""; let latestHelmErr = "";
const options = {}; const options = {};
@ -128,15 +129,13 @@ function getLatestHelmVersion() {
} }
}; };
yield exec.exec(command, [], options); yield exec.exec(command, [], options);
if (latestHelmErr !== "") if (latestHelmErr !== "" || isValidVersion(latestHelm))
return getStableHelmVersion(); return getStableHelmVersion();
return latestHelm; return latestHelm;
}); });
} }
// isValidVersion checks if verison matches the specified type and is a stable release // isValidVersion checks if verison matches the specified type and is a stable release
function isValidVersion(version, type) { function isValidVersion(version) {
if (!version.toLocaleLowerCase().startsWith(type))
return false;
return version.indexOf('rc') == -1; return version.indexOf('rc') == -1;
} }
function findHelm(rootFolder) { function findHelm(rootFolder) {

View file

@ -105,8 +105,9 @@ export async function downloadHelm(version: string): Promise<string> {
return helmpath; return helmpath;
} }
// getLatestHelmVersion uses cURL and regex to scrape the latest version
async function getLatestHelmVersion(): Promise<string>{ async function getLatestHelmVersion(): Promise<string>{
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 latestHelm: string = "";
let latestHelmErr: string = ""; let latestHelmErr: string = "";
@ -123,14 +124,12 @@ async function getLatestHelmVersion(): Promise<string>{
await exec.exec(command, [], options); await exec.exec(command, [], options);
if(latestHelmErr !== "") return getStableHelmVersion(); if(latestHelmErr !== "" || isValidVersion(latestHelm)) return getStableHelmVersion();
return latestHelm; return latestHelm;
} }
// isValidVersion checks if verison matches the specified type and is a stable release // isValidVersion checks if verison matches the specified type and is a stable release
function isValidVersion(version: string, type: string): boolean { function isValidVersion(version: string): boolean {
if (!version.toLocaleLowerCase().startsWith(type))
return false;
return version.indexOf('rc') == -1; return version.indexOf('rc') == -1;
} }