mirror of
https://github.com/Azure/setup-helm.git
synced 2025-09-07 20:46:32 +00:00
Changing feature flag name
This commit is contained in:
33
lib/run.js
33
lib/run.js
@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// Copyright (c) Microsoft Corporation.
|
// Copyright (c) Microsoft Corporation.
|
||||||
|
// Copyright (c) Microsoft Corporation.
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
@ -137,14 +138,14 @@ function getLatestHelmVersionFor(type) {
|
|||||||
const token = core.getInput('token', { 'required': true });
|
const token = core.getInput('token', { 'required': true });
|
||||||
try {
|
try {
|
||||||
const { repository } = yield graphql_1.graphql(`{
|
const { repository } = yield graphql_1.graphql(`{
|
||||||
repository(name:"helm", owner:"helm") {
|
repository(name: "helm", owner: "helm") {
|
||||||
releases(last: 100) {
|
releases(last: 100) {
|
||||||
nodes {
|
nodes {
|
||||||
tagName
|
tagName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`, {
|
}`, {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: `token ${token}`
|
authorization: `token ${token}`
|
||||||
}
|
}
|
||||||
@ -185,20 +186,20 @@ 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 (process.env['HELM_INSTALLER_LEGACY_VERSIONING'] == 'true') {
|
||||||
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
version = yield getLatestHelmVersionFor("v3");
|
version = yield getStableHelmVersion();
|
||||||
}
|
|
||||||
else if (version === LATEST_HELM2_VERSION) {
|
|
||||||
version = yield getLatestHelmVersionFor("v2");
|
|
||||||
}
|
}
|
||||||
else if (!version.toLocaleLowerCase().startsWith('v')) {
|
else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||||
version = 'v' + version;
|
version = 'v' + version;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (version.toLocaleLowerCase() === 'latest') {
|
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
||||||
version = yield getStableHelmVersion();
|
version = yield getLatestHelmVersionFor("v3");
|
||||||
|
}
|
||||||
|
else if (version === LATEST_HELM2_VERSION) {
|
||||||
|
version = yield getLatestHelmVersionFor("v2");
|
||||||
}
|
}
|
||||||
else if (!version.toLocaleLowerCase().startsWith('v')) {
|
else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||||
version = 'v' + version;
|
version = 'v' + version;
|
||||||
|
148
src/run.ts
148
src/run.ts
@ -21,24 +21,24 @@ const LATEST_HELM3_VERSION = '3.*';
|
|||||||
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
|
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/)) {
|
||||||
return '.exe';
|
return '.exe';
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHelmDownloadURL(version: string): string {
|
function getHelmDownloadURL(version: string): string {
|
||||||
switch (os.type()) {
|
switch (os.type()) {
|
||||||
case 'Linux':
|
case 'Linux':
|
||||||
return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version);
|
return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version);
|
||||||
|
|
||||||
case 'Darwin':
|
case 'Darwin':
|
||||||
return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version);
|
return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version);
|
||||||
|
|
||||||
case 'Windows_NT':
|
case 'Windows_NT':
|
||||||
default:
|
default:
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStableHelmVersion(): Promise<string> {
|
export async function getStableHelmVersion(): Promise<string> {
|
||||||
@ -67,45 +67,45 @@ export async function getStableHelmVersion(): Promise<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 || [];
|
||||||
files.forEach(function (file) {
|
files.forEach(function (file) {
|
||||||
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||||
filelist = walkSync(path.join(dir, file), filelist, fileToFind);
|
filelist = walkSync(path.join(dir, file), filelist, fileToFind);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.debug(file);
|
core.debug(file);
|
||||||
if (file == fileToFind) {
|
if (file == fileToFind) {
|
||||||
filelist.push(path.join(dir, file));
|
filelist.push(path.join(dir, file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return filelist;
|
return filelist;
|
||||||
};
|
};
|
||||||
|
|
||||||
async function downloadHelm(version: string): Promise<string> {
|
async function downloadHelm(version: string): Promise<string> {
|
||||||
if (!version) { version = await getLatestHelmVersionFor("v3"); }
|
if (!version) { version = await getLatestHelmVersionFor("v3"); }
|
||||||
let cachedToolpath = toolCache.find(helmToolName, version);
|
let cachedToolpath = toolCache.find(helmToolName, version);
|
||||||
if (!cachedToolpath) {
|
if (!cachedToolpath) {
|
||||||
let helmDownloadPath;
|
let helmDownloadPath;
|
||||||
try {
|
try {
|
||||||
helmDownloadPath = await toolCache.downloadTool(getHelmDownloadURL(version));
|
helmDownloadPath = await toolCache.downloadTool(getHelmDownloadURL(version));
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
throw new Error(util.format("Failed to download Helm from location ", getHelmDownloadURL(version)));
|
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 helmpath = findHelm(cachedToolpath);
|
||||||
const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath);
|
if (!helmpath) {
|
||||||
cachedToolpath = await toolCache.cacheDir(unzipedHelmPath, helmToolName, version);
|
throw new Error(util.format("Helm executable not found in path ", cachedToolpath));
|
||||||
}
|
}
|
||||||
|
|
||||||
const helmpath = findHelm(cachedToolpath);
|
fs.chmodSync(helmpath, '777');
|
||||||
if (!helmpath) {
|
return helmpath;
|
||||||
throw new Error(util.format("Helm executable not found in path ", cachedToolpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.chmodSync(helmpath, '777');
|
|
||||||
return helmpath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLatestHelmVersionFor(type: string): Promise<string> {
|
async function getLatestHelmVersionFor(type: string): Promise<string> {
|
||||||
@ -113,14 +113,14 @@ async function getLatestHelmVersionFor(type: string): Promise<string> {
|
|||||||
try {
|
try {
|
||||||
const { repository } = await graphql(
|
const { repository } = await graphql(
|
||||||
`{
|
`{
|
||||||
repository(name:"helm", owner:"helm") {
|
repository(name: "helm", owner: "helm") {
|
||||||
releases(last: 100) {
|
releases(last: 100) {
|
||||||
nodes {
|
nodes {
|
||||||
tagName
|
tagName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`,
|
}`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
authorization: `token ${token}`
|
authorization: `token ${token}`
|
||||||
@ -152,31 +152,31 @@ function isValidVersion(version: string, type: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function findHelm(rootFolder: string): string {
|
function findHelm(rootFolder: string): string {
|
||||||
fs.chmodSync(rootFolder, '777');
|
fs.chmodSync(rootFolder, '777');
|
||||||
var filelist: string[] = [];
|
var filelist: string[] = [];
|
||||||
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
|
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
|
||||||
if (!filelist) {
|
if (!filelist) {
|
||||||
throw new Error(util.format("Helm executable not found in path ", rootFolder));
|
throw new Error(util.format("Helm executable not found in path ", rootFolder));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return filelist[0];
|
return filelist[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (process.env['HELM_INSTALLER_LEGACY_VERSIONING'] == 'true') {
|
||||||
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
version = await getLatestHelmVersionFor("v3");
|
version = await getStableHelmVersion();
|
||||||
} else if (version === LATEST_HELM2_VERSION) {
|
|
||||||
version = await getLatestHelmVersionFor("v2");
|
|
||||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||||
version = 'v' + version;
|
version = 'v' + version;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (version.toLocaleLowerCase() === 'latest') {
|
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
||||||
version = await getStableHelmVersion();
|
version = await getLatestHelmVersionFor("v3");
|
||||||
|
} else if (version === LATEST_HELM2_VERSION) {
|
||||||
|
version = await getLatestHelmVersionFor("v2");
|
||||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||||
version = 'v' + version;
|
version = 'v' + version;
|
||||||
}
|
}
|
||||||
@ -194,13 +194,9 @@ async function run() {
|
|||||||
catch {
|
catch {
|
||||||
//do nothing, set as output variable
|
//do nothing, set as output variable
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch {
|
|
||||||
//do nothing, set as output variable
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`);
|
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`);
|
||||||
core.setOutput('helm-path', cachedPath);
|
core.setOutput('helm-path', cachedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(core.setFailed);
|
run().catch(core.setFailed);
|
Reference in New Issue
Block a user