4
0
Fork 0
mirror of https://github.com/Azure/setup-helm.git synced 2025-11-07 13:06: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;
// 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) {

View file

@ -105,8 +105,9 @@ export async function downloadHelm(version: string): Promise<string> {
return helmpath;
}
// getLatestHelmVersion uses cURL and regex to scrape the latest version
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 latestHelmErr: string = "";
@ -123,14 +124,12 @@ async function getLatestHelmVersion(): Promise<string>{
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;
}