4
0
Fork 0
mirror of https://github.com/Azure/setup-helm.git synced 2025-11-08 05:26:56 +00:00

add arm64 support

This commit is contained in:
Oliver King 2022-02-04 09:20:54 -05:00
parent 7e6f48e5b4
commit 3a88d40c83

View file

@ -2,22 +2,22 @@
// 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 toolCache from '@actions/tool-cache'; import * as toolCache from "@actions/tool-cache";
import * as core from '@actions/core'; import * as core from "@actions/core";
const helmToolName = 'helm'; const helmToolName = "helm";
const stableHelmVersion = 'v3.8.0'; const stableHelmVersion = "v3.8.0";
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases'; const helmAllReleasesUrl = "https://api.github.com/repos/helm/helm/releases";
export async function run() { export async function run() {
let version = core.getInput('version', { 'required': true }); let version = core.getInput("version", { required: true });
if (version.toLocaleLowerCase() === 'latest') { if (version.toLocaleLowerCase() === "latest") {
version = await getLatestHelmVersion(); version = await getLatestHelmVersion();
} }
@ -25,17 +25,17 @@ export async function run() {
let cachedPath = await downloadHelm(version); let cachedPath = await downloadHelm(version);
try { try {
if (!process.env["PATH"].startsWith(path.dirname(cachedPath))) {
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
core.addPath(path.dirname(cachedPath)); core.addPath(path.dirname(cachedPath));
} }
} } catch {
catch {
//do nothing, set as output variable //do nothing, set as output variable
} }
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`); console.log(
core.setOutput('helm-path', cachedPath); `Helm tool version: '${version}' has been cached at ${cachedPath}`
);
core.setOutput("helm-path", cachedPath);
} }
// Downloads the helm releases JSON and parses all the recent versions of helm from it. // Downloads the helm releases JSON and parses all the recent versions of helm from it.
@ -45,14 +45,20 @@ export async function getLatestHelmVersion(): Promise<string> {
const helmJSONPath: string = await toolCache.downloadTool(helmAllReleasesUrl); const helmJSONPath: string = await toolCache.downloadTool(helmAllReleasesUrl);
try { try {
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8')) const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, "utf-8"));
for(let i in helmJSON) { for (let i in helmJSON) {
if(isValidVersion(helmJSON[i].tag_name)) { if (isValidVersion(helmJSON[i].tag_name)) {
return helmJSON[i].tag_name; return helmJSON[i].tag_name;
} }
} }
} catch(err) { } catch (err) {
core.warning(util.format("Error while fetching the latest Helm release. Error: %s. Using default Helm version %s", err.toString(), stableHelmVersion)); 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;
} }
@ -61,27 +67,53 @@ export async function getLatestHelmVersion(): Promise<string> {
// isValidVersion checks if verison is a stable release // isValidVersion checks if verison is a stable release
function isValidVersion(version: string): boolean { function isValidVersion(version: string): boolean {
return version.indexOf('rc') == -1; return version.indexOf("rc") == -1;
} }
export function getExecutableExtension(): string { export function getExecutableExtension(): string {
if (os.type().match(/^Win/)) { if (os.type().match(/^Win/)) {
return '.exe'; return ".exe";
} }
return ''; return "";
} }
const LINUX = "Linux";
const MAC_OS = "Darwin";
const WINDOWS = "Windows_NT";
const ARM64 = "arm64";
export function getHelmDownloadURL(version: string): string { export function getHelmDownloadURL(version: string): string {
switch (os.type()) { const arch = os.arch();
case 'Linux': const operatingSystem = os.type();
return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version);
case 'Darwin': switch (true) {
return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version); case operatingSystem == LINUX && arch == ARM64:
return util.format(
"https://get.helm.sh/helm-%s-linux-arm64.zip",
version
);
case operatingSystem == LINUX:
return util.format(
"https://get.helm.sh/helm-%s-linux-amd64.zip",
version
);
case 'Windows_NT': case operatingSystem == MAC_OS && arch == ARM64:
return util.format(
"https://get.helm.sh/helm-%s-darwin-arm64.zip",
version
);
case operatingSystem == MAC_OS:
return util.format(
"https://get.helm.sh/helm-%s-darwin-amd64.zip",
version
);
case operatingSystem == WINDOWS:
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
);
} }
} }
@ -90,33 +122,47 @@ export async function downloadHelm(version: string): Promise<string> {
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'); fs.chmodSync(helmDownloadPath, "777");
const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath); const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath);
cachedToolpath = await toolCache.cacheDir(unzipedHelmPath, helmToolName, version); cachedToolpath = await toolCache.cacheDir(
unzipedHelmPath,
helmToolName,
version
);
} }
const helmpath = findHelm(cachedToolpath); const helmpath = findHelm(cachedToolpath);
if (!helmpath) { if (!helmpath) {
throw new Error(util.format("Helm executable not found in path", cachedToolpath)); throw new Error(
util.format("Helm executable not found in path", cachedToolpath)
);
} }
fs.chmodSync(helmpath, '777'); fs.chmodSync(helmpath, "777");
return helmpath; return helmpath;
} }
export function findHelm(rootFolder: string): string { export 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 || filelist.length == 0) { if (!filelist || filelist.length == 0) {
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];
} }
} }
@ -127,8 +173,7 @@ export var walkSync = function (dir, filelist, fileToFind) {
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));