mirror of
https://github.com/Azure/setup-helm.git
synced 2026-04-07 23:10:08 +00:00
Adding feature flag as environment variable in release
This commit is contained in:
parent
adf7ced229
commit
80c57e0303
2 changed files with 103 additions and 22 deletions
71
src/run.ts
71
src/run.ts
|
|
@ -1,10 +1,12 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as fs from 'fs';
|
||||
import * as semver from 'semver';
|
||||
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
|
|
@ -16,6 +18,7 @@ const stableHelm3Version = 'v3.5.3';
|
|||
const stableHelm2Version = 'v2.17.0';
|
||||
const LATEST_HELM2_VERSION = '2.*';
|
||||
const LATEST_HELM3_VERSION = '3.*';
|
||||
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
|
||||
|
||||
function getExecutableExtension(): string {
|
||||
if (os.type().match(/^Win/)) {
|
||||
|
|
@ -38,6 +41,31 @@ function getHelmDownloadURL(version: string): string {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getStableHelmVersion(): Promise<string> {
|
||||
try {
|
||||
const downloadPath = await 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;
|
||||
}
|
||||
|
||||
var walkSync = function (dir, filelist, fileToFind) {
|
||||
var files = fs.readdirSync(dir);
|
||||
filelist = filelist || [];
|
||||
|
|
@ -113,14 +141,14 @@ async function getLatestHelmVersionFor(type: string): Promise<string> {
|
|||
}
|
||||
|
||||
function getStableHelmVersionFor(type: string) {
|
||||
return type==="v2" ? stableHelm2Version : stableHelm3Version;
|
||||
return type === "v2" ? stableHelm2Version : stableHelm3Version;
|
||||
}
|
||||
|
||||
// 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;
|
||||
return version.indexOf('rc') == -1
|
||||
return version.indexOf('rc') == -1;
|
||||
}
|
||||
|
||||
function findHelm(rootFolder: string): string {
|
||||
|
|
@ -136,22 +164,35 @@ function findHelm(rootFolder: string): string {
|
|||
}
|
||||
|
||||
async function run() {
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
||||
version = await getLatestHelmVersionFor("v3");
|
||||
} else if (version === LATEST_HELM2_VERSION) {
|
||||
version = await getLatestHelmVersionFor("v2");
|
||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||
version = 'v' + version;
|
||||
}
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
|
||||
core.debug(util.format("Downloading %s", version));
|
||||
let cachedPath = await downloadHelm(version);
|
||||
if (process.env['NEW_VERSION_LOGIC'] == 'true') {
|
||||
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
||||
version = await getLatestHelmVersionFor("v3");
|
||||
} else if (version === LATEST_HELM2_VERSION) {
|
||||
version = await getLatestHelmVersionFor("v2");
|
||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||
version = 'v' + version;
|
||||
}
|
||||
} else {
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = await getStableHelmVersion();
|
||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||
version = 'v' + version;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
core.debug(util.format("Downloading %s", version));
|
||||
let cachedPath = await downloadHelm(version);
|
||||
|
||||
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
||||
core.addPath(path.dirname(cachedPath));
|
||||
try {
|
||||
|
||||
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
||||
core.addPath(path.dirname(cachedPath));
|
||||
}
|
||||
}
|
||||
catch {
|
||||
//do nothing, set as output variable
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue