mirror of
https://github.com/Azure/setup-helm.git
synced 2025-07-16 10:50:38 +00:00
Adding feature flag as environment variable
This commit is contained in:
40
lib/run.js
40
lib/run.js
@ -30,10 +30,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
exports.getStableHelmVersion = void 0;
|
||||||
const os = __importStar(require("os"));
|
const os = __importStar(require("os"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const util = __importStar(require("util"));
|
const util = __importStar(require("util"));
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
|
const semver = __importStar(require("semver"));
|
||||||
const toolCache = __importStar(require("@actions/tool-cache"));
|
const toolCache = __importStar(require("@actions/tool-cache"));
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const graphql_1 = require("@octokit/graphql");
|
const graphql_1 = require("@octokit/graphql");
|
||||||
@ -43,6 +45,7 @@ const stableHelm3Version = 'v3.5.3';
|
|||||||
const stableHelm2Version = 'v2.17.0';
|
const stableHelm2Version = 'v2.17.0';
|
||||||
const LATEST_HELM2_VERSION = '2.*';
|
const LATEST_HELM2_VERSION = '2.*';
|
||||||
const LATEST_HELM3_VERSION = '3.*';
|
const LATEST_HELM3_VERSION = '3.*';
|
||||||
|
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
|
||||||
function getExecutableExtension() {
|
function getExecutableExtension() {
|
||||||
if (os.type().match(/^Win/)) {
|
if (os.type().match(/^Win/)) {
|
||||||
return '.exe';
|
return '.exe';
|
||||||
@ -60,6 +63,33 @@ function getHelmDownloadURL(version) {
|
|||||||
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
var walkSync = function (dir, filelist, fileToFind) {
|
var walkSync = function (dir, filelist, fileToFind) {
|
||||||
var files = fs.readdirSync(dir);
|
var files = fs.readdirSync(dir);
|
||||||
filelist = filelist || [];
|
filelist = filelist || [];
|
||||||
@ -155,6 +185,7 @@ function findHelm(rootFolder) {
|
|||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let version = core.getInput('version', { 'required': true });
|
let version = core.getInput('version', { 'required': true });
|
||||||
|
if (process.env['NEW_VERSION_LOGIC'] == 'true') {
|
||||||
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
||||||
version = yield getLatestHelmVersionFor("v3");
|
version = yield getLatestHelmVersionFor("v3");
|
||||||
}
|
}
|
||||||
@ -164,6 +195,15 @@ function run() {
|
|||||||
else if (!version.toLocaleLowerCase().startsWith('v')) {
|
else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||||
version = 'v' + version;
|
version = 'v' + version;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
|
version = yield getStableHelmVersion();
|
||||||
|
}
|
||||||
|
else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||||
|
version = 'v' + version;
|
||||||
|
}
|
||||||
|
}
|
||||||
core.debug(util.format("Downloading %s", version));
|
core.debug(util.format("Downloading %s", version));
|
||||||
let cachedPath = yield downloadHelm(version);
|
let cachedPath = yield downloadHelm(version);
|
||||||
try {
|
try {
|
||||||
|
39
src/run.ts
39
src/run.ts
@ -1,10 +1,12 @@
|
|||||||
// Copyright (c) Microsoft Corporation.
|
// Copyright (c) Microsoft Corporation.
|
||||||
|
// Copyright (c) Microsoft Corporation.
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as semver from 'semver';
|
||||||
|
|
||||||
import * as toolCache from '@actions/tool-cache';
|
import * as toolCache from '@actions/tool-cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
@ -16,6 +18,7 @@ const stableHelm3Version = 'v3.5.3';
|
|||||||
const stableHelm2Version = 'v2.17.0';
|
const stableHelm2Version = 'v2.17.0';
|
||||||
const LATEST_HELM2_VERSION = '2.*';
|
const LATEST_HELM2_VERSION = '2.*';
|
||||||
const LATEST_HELM3_VERSION = '3.*';
|
const LATEST_HELM3_VERSION = '3.*';
|
||||||
|
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
|
||||||
|
|
||||||
function getExecutableExtension(): string {
|
function getExecutableExtension(): string {
|
||||||
if (os.type().match(/^Win/)) {
|
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 walkSync = function (dir, filelist, fileToFind) {
|
||||||
var files = fs.readdirSync(dir);
|
var files = fs.readdirSync(dir);
|
||||||
filelist = filelist || [];
|
filelist = filelist || [];
|
||||||
@ -120,7 +148,7 @@ function getStableHelmVersionFor(type: string) {
|
|||||||
function isValidVersion(version: string, type: string): boolean {
|
function isValidVersion(version: string, type: string): boolean {
|
||||||
if (!version.toLocaleLowerCase().startsWith(type))
|
if (!version.toLocaleLowerCase().startsWith(type))
|
||||||
return false;
|
return false;
|
||||||
return version.indexOf('rc') == -1
|
return version.indexOf('rc') == -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function findHelm(rootFolder: string): string {
|
function findHelm(rootFolder: string): string {
|
||||||
@ -137,6 +165,8 @@ function findHelm(rootFolder: string): string {
|
|||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
let version = core.getInput('version', { 'required': true });
|
let version = core.getInput('version', { 'required': true });
|
||||||
|
|
||||||
|
if (process.env['NEW_VERSION_LOGIC'] == 'true') {
|
||||||
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
||||||
version = await getLatestHelmVersionFor("v3");
|
version = await getLatestHelmVersionFor("v3");
|
||||||
} else if (version === LATEST_HELM2_VERSION) {
|
} else if (version === LATEST_HELM2_VERSION) {
|
||||||
@ -144,6 +174,13 @@ async function run() {
|
|||||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||||
version = 'v' + version;
|
version = 'v' + version;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
|
version = await getStableHelmVersion();
|
||||||
|
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||||
|
version = 'v' + version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
core.debug(util.format("Downloading %s", version));
|
core.debug(util.format("Downloading %s", version));
|
||||||
let cachedPath = await downloadHelm(version);
|
let cachedPath = await downloadHelm(version);
|
||||||
|
Reference in New Issue
Block a user