10
0
Fork 0
mirror of https://github.com/Azure/setup-helm.git synced 2026-04-14 02:24:48 +00:00

Latest getLatestHelmVersion iteration

This commit is contained in:
Asa Gayle 2022-01-25 10:34:19 -05:00
parent 363e4253a0
commit f1588f7abf
4 changed files with 7544 additions and 55 deletions

View file

@ -18,11 +18,10 @@ const path = require("path");
const util = require("util");
const fs = require("fs");
const semver = require("semver");
const exec = require("@actions/exec");
const toolCache = require("@actions/tool-cache");
const core = require("@actions/core");
const helmToolName = 'helm';
const stableHelmVersion = 'v3.7.2';
const stableHelmVersion = 'v3.8.0';
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
function getExecutableExtension() {
if (os.type().match(/^Win/)) {
@ -113,27 +112,20 @@ 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* () {
console.log("Test");
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/".*//'`;
let latestHelm = "";
let latestHelmErr = "";
const options = {};
options.listeners = {
stdout: (data) => {
latestHelm += data.toString();
},
stderr: (data) => {
latestHelmErr += data.toString();
let helmJSONPath = yield toolCache.downloadTool("https://api.github.com/repos/helm/helm/releases");
let versions;
const helmJSONArray = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'));
for (const i in helmJSONArray) {
versions.push(helmJSONArray[i]["tag_name"]);
}
for (const v in versions) {
if (isValidVersion(v)) {
return v;
}
};
yield exec.exec(command, [], options);
console.log("latestHelm");
if (latestHelmErr !== "" || !isValidVersion(latestHelm))
return getStableHelmVersion();
return latestHelm;
}
return stableHelmVersion;
});
}
exports.getLatestHelmVersion = getLatestHelmVersion;