From 4420cb2ff7c9d3390f4a79d1f1c95dca30bc9009 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Tue, 30 Mar 2021 21:22:57 +0530 Subject: [PATCH] Changing feature flag name --- lib/run.js | 33 ++++++------ src/run.ts | 148 ++++++++++++++++++++++++++--------------------------- 2 files changed, 89 insertions(+), 92 deletions(-) diff --git a/lib/run.js b/lib/run.js index bf4f17f..9953953 100644 --- a/lib/run.js +++ b/lib/run.js @@ -1,5 +1,6 @@ "use strict"; // Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT license. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; @@ -137,14 +138,14 @@ function getLatestHelmVersionFor(type) { const token = core.getInput('token', { 'required': true }); try { const { repository } = yield graphql_1.graphql(`{ - repository(name:"helm", owner:"helm") { - releases(last: 100) { - nodes { - tagName - } - } - } - }`, { + repository(name: "helm", owner: "helm") { + releases(last: 100) { + nodes { + tagName + } + } + } + }`, { headers: { authorization: `token ${token}` } @@ -185,20 +186,20 @@ function findHelm(rootFolder) { function run() { return __awaiter(this, void 0, void 0, function* () { let version = core.getInput('version', { 'required': true }); - if (process.env['NEW_VERSION_LOGIC'] == 'true') { - if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) { - version = yield getLatestHelmVersionFor("v3"); - } - else if (version === LATEST_HELM2_VERSION) { - version = yield getLatestHelmVersionFor("v2"); + if (process.env['HELM_INSTALLER_LEGACY_VERSIONING'] == 'true') { + if (version.toLocaleLowerCase() === 'latest') { + version = yield getStableHelmVersion(); } else if (!version.toLocaleLowerCase().startsWith('v')) { version = 'v' + version; } } else { - if (version.toLocaleLowerCase() === 'latest') { - version = yield getStableHelmVersion(); + if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) { + version = yield getLatestHelmVersionFor("v3"); + } + else if (version === LATEST_HELM2_VERSION) { + version = yield getLatestHelmVersionFor("v2"); } else if (!version.toLocaleLowerCase().startsWith('v')) { version = 'v' + version; diff --git a/src/run.ts b/src/run.ts index e517f28..c689085 100644 --- a/src/run.ts +++ b/src/run.ts @@ -21,24 +21,24 @@ const LATEST_HELM3_VERSION = '3.*'; const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases'; function getExecutableExtension(): string { - if (os.type().match(/^Win/)) { - return '.exe'; - } - return ''; + if (os.type().match(/^Win/)) { + return '.exe'; + } + return ''; } function getHelmDownloadURL(version: string): string { - switch (os.type()) { - case 'Linux': - return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version); + switch (os.type()) { + case 'Linux': + return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version); - case 'Darwin': - return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version); + case 'Darwin': + return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version); - case 'Windows_NT': - default: - return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version); - } + case 'Windows_NT': + default: + return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version); + } } export async function getStableHelmVersion(): Promise { @@ -67,45 +67,45 @@ export async function getStableHelmVersion(): Promise { } var walkSync = function (dir, filelist, fileToFind) { - var files = fs.readdirSync(dir); - filelist = filelist || []; - files.forEach(function (file) { - if (fs.statSync(path.join(dir, file)).isDirectory()) { - filelist = walkSync(path.join(dir, file), filelist, fileToFind); - } - else { - core.debug(file); - if (file == fileToFind) { - filelist.push(path.join(dir, file)); - } - } - }); - return filelist; + var files = fs.readdirSync(dir); + filelist = filelist || []; + files.forEach(function (file) { + if (fs.statSync(path.join(dir, file)).isDirectory()) { + filelist = walkSync(path.join(dir, file), filelist, fileToFind); + } + else { + core.debug(file); + if (file == fileToFind) { + filelist.push(path.join(dir, file)); + } + } + }); + return filelist; }; async function downloadHelm(version: string): Promise { - if (!version) { version = await getLatestHelmVersionFor("v3"); } - let cachedToolpath = toolCache.find(helmToolName, version); - if (!cachedToolpath) { - let helmDownloadPath; - try { - helmDownloadPath = await toolCache.downloadTool(getHelmDownloadURL(version)); - } catch (exception) { - throw new Error(util.format("Failed to download Helm from location ", getHelmDownloadURL(version))); + if (!version) { version = await getLatestHelmVersionFor("v3"); } + let cachedToolpath = toolCache.find(helmToolName, version); + if (!cachedToolpath) { + let helmDownloadPath; + try { + helmDownloadPath = await toolCache.downloadTool(getHelmDownloadURL(version)); + } catch (exception) { + throw new Error(util.format("Failed to download Helm from location ", getHelmDownloadURL(version))); + } + + fs.chmodSync(helmDownloadPath, '777'); + const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath); + cachedToolpath = await toolCache.cacheDir(unzipedHelmPath, helmToolName, version); } - fs.chmodSync(helmDownloadPath, '777'); - const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath); - cachedToolpath = await toolCache.cacheDir(unzipedHelmPath, helmToolName, version); - } + const helmpath = findHelm(cachedToolpath); + if (!helmpath) { + throw new Error(util.format("Helm executable not found in path ", cachedToolpath)); + } - const helmpath = findHelm(cachedToolpath); - if (!helmpath) { - throw new Error(util.format("Helm executable not found in path ", cachedToolpath)); - } - - fs.chmodSync(helmpath, '777'); - return helmpath; + fs.chmodSync(helmpath, '777'); + return helmpath; } async function getLatestHelmVersionFor(type: string): Promise { @@ -113,14 +113,14 @@ async function getLatestHelmVersionFor(type: string): Promise { try { const { repository } = await graphql( `{ - repository(name:"helm", owner:"helm") { - releases(last: 100) { - nodes { - tagName - } - } - } - }`, + repository(name: "helm", owner: "helm") { + releases(last: 100) { + nodes { + tagName + } + } + } + }`, { headers: { authorization: `token ${token}` @@ -152,31 +152,31 @@ function isValidVersion(version: string, type: string): boolean { } function findHelm(rootFolder: string): string { - fs.chmodSync(rootFolder, '777'); - var filelist: string[] = []; - walkSync(rootFolder, filelist, helmToolName + getExecutableExtension()); - if (!filelist) { - throw new Error(util.format("Helm executable not found in path ", rootFolder)); - } - else { - return filelist[0]; - } + fs.chmodSync(rootFolder, '777'); + var filelist: string[] = []; + walkSync(rootFolder, filelist, helmToolName + getExecutableExtension()); + if (!filelist) { + throw new Error(util.format("Helm executable not found in path ", rootFolder)); + } + else { + return filelist[0]; + } } async function run() { let version = core.getInput('version', { 'required': true }); - 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"); + if (process.env['HELM_INSTALLER_LEGACY_VERSIONING'] == 'true') { + if (version.toLocaleLowerCase() === 'latest') { + version = await getStableHelmVersion(); } else if (!version.toLocaleLowerCase().startsWith('v')) { version = 'v' + version; } } else { - if (version.toLocaleLowerCase() === 'latest') { - version = await getStableHelmVersion(); + 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; } @@ -194,13 +194,9 @@ async function run() { catch { //do nothing, set as output variable } - } - catch { - //do nothing, set as output variable - } - console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`); - core.setOutput('helm-path', cachedPath); + console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`); + core.setOutput('helm-path', cachedPath); } run().catch(core.setFailed); \ No newline at end of file