mirror of
https://github.com/Azure/setup-helm.git
synced 2026-04-14 10:34:47 +00:00
getLatestHelmVersion refactor
This commit is contained in:
parent
822c0c23d0
commit
45f20ed080
3 changed files with 32 additions and 108 deletions
54
lib/run.js
54
lib/run.js
|
|
@ -12,12 +12,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.run = exports.findHelm = exports.getLatestHelmVersion = exports.downloadHelm = exports.walkSync = exports.getStableHelmVersion = exports.getHelmDownloadURL = exports.getExecutableExtension = void 0;
|
||||
exports.run = exports.findHelm = exports.getLatestHelmVersion = exports.downloadHelm = exports.walkSync = exports.getHelmDownloadURL = exports.getExecutableExtension = void 0;
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const util = require("util");
|
||||
const fs = require("fs");
|
||||
const semver = require("semver");
|
||||
const toolCache = require("@actions/tool-cache");
|
||||
const core = require("@actions/core");
|
||||
const helmToolName = 'helm';
|
||||
|
|
@ -42,33 +41,6 @@ function getHelmDownloadURL(version) {
|
|||
}
|
||||
}
|
||||
exports.getHelmDownloadURL = getHelmDownloadURL;
|
||||
function getStableHelmVersion() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const downloadPath = yield toolCache.downloadTool(helmAllReleasesUrl);
|
||||
const responseArray = JSON.parse(fs.readFileSync(downloadPath, 'utf8').toString().trim());
|
||||
let latestHelmVersion = semver.clean(stableHelmVersion);
|
||||
responseArray.forEach(response => {
|
||||
if (response && response.tag_name) {
|
||||
let currentHelmVerison = semver.clean(response.tag_name.toString());
|
||||
if (currentHelmVerison) {
|
||||
if (currentHelmVerison.toString().indexOf('rc') == -1 && semver.gt(currentHelmVerison, latestHelmVersion)) {
|
||||
//If current helm version is not a pre release and is greater than latest helm version
|
||||
latestHelmVersion = currentHelmVerison;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
latestHelmVersion = "v" + latestHelmVersion;
|
||||
return latestHelmVersion;
|
||||
}
|
||||
catch (error) {
|
||||
core.warning(util.format("Cannot get the latest Helm info from %s. Error %s. Using default Helm version %s.", helmAllReleasesUrl, error, stableHelmVersion));
|
||||
}
|
||||
return stableHelmVersion;
|
||||
});
|
||||
}
|
||||
exports.getStableHelmVersion = getStableHelmVersion;
|
||||
exports.walkSync = function (dir, filelist, fileToFind) {
|
||||
var files = fs.readdirSync(dir);
|
||||
filelist = filelist || [];
|
||||
|
|
@ -88,7 +60,7 @@ exports.walkSync = function (dir, filelist, fileToFind) {
|
|||
function downloadHelm(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!version) {
|
||||
version = yield getStableHelmVersion();
|
||||
version = yield getLatestHelmVersion();
|
||||
}
|
||||
let cachedToolpath = toolCache.find(helmToolName, version);
|
||||
if (!cachedToolpath) {
|
||||
|
|
@ -112,18 +84,22 @@ function downloadHelm(version) {
|
|||
});
|
||||
}
|
||||
exports.downloadHelm = downloadHelm;
|
||||
// Downloads the helm release JSON and parses all the recent versions of helm from it.
|
||||
// Defaults to sending stable helm version if none are valid.
|
||||
function getLatestHelmVersion() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
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"]);
|
||||
let helmJSONPath = yield toolCache.downloadTool(helmAllReleasesUrl);
|
||||
try {
|
||||
const helmJSONArray = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'));
|
||||
helmJSONArray.forEach(ver => {
|
||||
if (isValidVersion(ver["tag_name"])) {
|
||||
return ver;
|
||||
}
|
||||
});
|
||||
}
|
||||
for (const v in versions) {
|
||||
if (isValidVersion(v)) {
|
||||
return v;
|
||||
}
|
||||
catch (err) {
|
||||
core.warning(util.format("Error while fetching the latest Helm release. Error: %s. Using default Helm version %s", err.toString(), stableHelmVersion));
|
||||
return stableHelmVersion;
|
||||
}
|
||||
return stableHelmVersion;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue