mirror of
https://github.com/Azure/setup-helm.git
synced 2025-11-07 21:16:57 +00:00
Requested changes
This commit is contained in:
parent
d2f4a46e94
commit
a277a45bd2
2 changed files with 159 additions and 163 deletions
121
lib/run.js
121
lib/run.js
|
|
@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.run = exports.findHelm = exports.getLatestHelmVersion = exports.downloadHelm = exports.walkSync = exports.getHelmDownloadURL = exports.getExecutableExtension = void 0;
|
exports.walkSync = exports.findHelm = exports.downloadHelm = exports.getHelmDownloadURL = exports.getExecutableExtension = exports.getLatestHelmVersion = exports.run = void 0;
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const util = require("util");
|
const util = require("util");
|
||||||
|
|
@ -22,6 +22,52 @@ const core = require("@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';
|
||||||
|
function run() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let version = core.getInput('version', { 'required': true });
|
||||||
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
|
version = yield getLatestHelmVersion();
|
||||||
|
}
|
||||||
|
core.debug(util.format("Downloading %s", version));
|
||||||
|
let cachedPath = yield downloadHelm(version);
|
||||||
|
try {
|
||||||
|
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
||||||
|
core.addPath(path.dirname(cachedPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (_a) {
|
||||||
|
//do nothing, set as output variable
|
||||||
|
}
|
||||||
|
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`);
|
||||||
|
core.setOutput('helm-path', cachedPath);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.run = run;
|
||||||
|
// Downloads the helm releases JSON and parses all the recent versions of helm from it.
|
||||||
|
// Defaults to sending stable helm version if none are valid or if it fails
|
||||||
|
function getLatestHelmVersion() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const helmJSONPath = yield toolCache.downloadTool(helmAllReleasesUrl);
|
||||||
|
try {
|
||||||
|
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'));
|
||||||
|
for (let i in helmJSON) {
|
||||||
|
if (isValidVersion(helmJSON[i].tag_name)) {
|
||||||
|
return helmJSON[i].tag_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.getLatestHelmVersion = getLatestHelmVersion;
|
||||||
|
// isValidVersion checks if verison is a stable release
|
||||||
|
function isValidVersion(version) {
|
||||||
|
return version.indexOf('rc') == -1;
|
||||||
|
}
|
||||||
function getExecutableExtension() {
|
function getExecutableExtension() {
|
||||||
if (os.type().match(/^Win/)) {
|
if (os.type().match(/^Win/)) {
|
||||||
return '.exe';
|
return '.exe';
|
||||||
|
|
@ -41,27 +87,8 @@ function getHelmDownloadURL(version) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.getHelmDownloadURL = getHelmDownloadURL;
|
exports.getHelmDownloadURL = getHelmDownloadURL;
|
||||||
exports.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 = exports.walkSync(path.join(dir, file), filelist, fileToFind);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.debug(file);
|
|
||||||
if (file == fileToFind) {
|
|
||||||
filelist.push(path.join(dir, file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return filelist;
|
|
||||||
};
|
|
||||||
function downloadHelm(version) {
|
function downloadHelm(version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (!version) {
|
|
||||||
version = yield getLatestHelmVersion();
|
|
||||||
}
|
|
||||||
let cachedToolpath = toolCache.find(helmToolName, version);
|
let cachedToolpath = toolCache.find(helmToolName, version);
|
||||||
if (!cachedToolpath) {
|
if (!cachedToolpath) {
|
||||||
let helmDownloadPath;
|
let helmDownloadPath;
|
||||||
|
|
@ -84,31 +111,6 @@ function downloadHelm(version) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.downloadHelm = downloadHelm;
|
exports.downloadHelm = downloadHelm;
|
||||||
// Downloads the helm releases JSON and parses all the recent versions of helm from it.
|
|
||||||
// Defaults to sending stable helm version if none are valid or if it fails
|
|
||||||
function getLatestHelmVersion() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let helmJSONPath = yield toolCache.downloadTool(helmAllReleasesUrl);
|
|
||||||
try {
|
|
||||||
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'));
|
|
||||||
for (let i in helmJSON) {
|
|
||||||
if (isValidVersion(helmJSON[i].tag_name)) {
|
|
||||||
return helmJSON[i].tag_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.getLatestHelmVersion = getLatestHelmVersion;
|
|
||||||
// isValidVersion checks if verison is a stable release
|
|
||||||
function isValidVersion(version) {
|
|
||||||
return version.indexOf('rc') == -1;
|
|
||||||
}
|
|
||||||
function findHelm(rootFolder) {
|
function findHelm(rootFolder) {
|
||||||
fs.chmodSync(rootFolder, '777');
|
fs.chmodSync(rootFolder, '777');
|
||||||
var filelist = [];
|
var filelist = [];
|
||||||
|
|
@ -121,25 +123,20 @@ function findHelm(rootFolder) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.findHelm = findHelm;
|
exports.findHelm = findHelm;
|
||||||
function run() {
|
exports.walkSync = function (dir, filelist, fileToFind) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
var files = fs.readdirSync(dir);
|
||||||
let version = core.getInput('version', { 'required': true });
|
filelist = filelist || [];
|
||||||
if (version.toLocaleLowerCase() === 'latest') {
|
files.forEach(function (file) {
|
||||||
version = yield getLatestHelmVersion();
|
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||||
|
filelist = exports.walkSync(path.join(dir, file), filelist, fileToFind);
|
||||||
}
|
}
|
||||||
core.debug(util.format("Downloading %s", version));
|
else {
|
||||||
let cachedPath = yield downloadHelm(version);
|
core.debug(file);
|
||||||
try {
|
if (file == fileToFind) {
|
||||||
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
filelist.push(path.join(dir, file));
|
||||||
core.addPath(path.dirname(cachedPath));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (_a) {
|
|
||||||
//do nothing, set as output variable
|
|
||||||
}
|
|
||||||
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`);
|
|
||||||
core.setOutput('helm-path', cachedPath);
|
|
||||||
});
|
});
|
||||||
}
|
return filelist;
|
||||||
exports.run = run;
|
};
|
||||||
run().catch(core.setFailed);
|
run().catch(core.setFailed);
|
||||||
|
|
|
||||||
201
src/run.ts
201
src/run.ts
|
|
@ -14,107 +14,6 @@ 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 function getExecutableExtension(): string {
|
|
||||||
if (os.type().match(/^Win/)) {
|
|
||||||
return '.exe';
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getHelmDownloadURL(version: string): string {
|
|
||||||
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 'Windows_NT':
|
|
||||||
default:
|
|
||||||
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function downloadHelm(version: string): Promise<string> {
|
|
||||||
if (!version) { version = await getLatestHelmVersion(); }
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
const helmpath = findHelm(cachedToolpath);
|
|
||||||
if (!helmpath) {
|
|
||||||
throw new Error(util.format("Helm executable not found in path", cachedToolpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.chmodSync(helmpath, '777');
|
|
||||||
return helmpath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Downloads the helm releases JSON and parses all the recent versions of helm from it.
|
|
||||||
// Defaults to sending stable helm version if none are valid or if it fails
|
|
||||||
|
|
||||||
export async function getLatestHelmVersion(): Promise<string> {
|
|
||||||
let helmJSONPath:string = await toolCache.downloadTool(helmAllReleasesUrl);
|
|
||||||
|
|
||||||
try{
|
|
||||||
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'))
|
|
||||||
for(let i in helmJSON){
|
|
||||||
if(isValidVersion(helmJSON[i].tag_name)){
|
|
||||||
return helmJSON[i].tag_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(err){
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// isValidVersion checks if verison is a stable release
|
|
||||||
function isValidVersion(version: string): boolean {
|
|
||||||
return version.indexOf('rc') == -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function findHelm(rootFolder: string): string {
|
|
||||||
fs.chmodSync(rootFolder, '777');
|
|
||||||
var filelist: string[] = [];
|
|
||||||
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
|
|
||||||
if (!filelist || filelist.length == 0) {
|
|
||||||
throw new Error(util.format("Helm executable not found in path", rootFolder));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return filelist[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
let version = core.getInput('version', { 'required': true });
|
let version = core.getInput('version', { 'required': true });
|
||||||
|
|
||||||
|
|
@ -139,4 +38,104 @@ export async function run() {
|
||||||
core.setOutput('helm-path', cachedPath);
|
core.setOutput('helm-path', cachedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Downloads the helm releases JSON and parses all the recent versions of helm from it.
|
||||||
|
// Defaults to sending stable helm version if none are valid or if it fails
|
||||||
|
|
||||||
|
export async function getLatestHelmVersion(): Promise<string> {
|
||||||
|
const helmJSONPath: string = await toolCache.downloadTool(helmAllReleasesUrl);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'))
|
||||||
|
for(let i in helmJSON) {
|
||||||
|
if(isValidVersion(helmJSON[i].tag_name)) {
|
||||||
|
return helmJSON[i].tag_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// isValidVersion checks if verison is a stable release
|
||||||
|
function isValidVersion(version: string): boolean {
|
||||||
|
return version.indexOf('rc') == -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getExecutableExtension(): string {
|
||||||
|
if (os.type().match(/^Win/)) {
|
||||||
|
return '.exe';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHelmDownloadURL(version: string): string {
|
||||||
|
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 'Windows_NT':
|
||||||
|
default:
|
||||||
|
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function downloadHelm(version: string): Promise<string> {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
const helmpath = findHelm(cachedToolpath);
|
||||||
|
if (!helmpath) {
|
||||||
|
throw new Error(util.format("Helm executable not found in path", cachedToolpath));
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.chmodSync(helmpath, '777');
|
||||||
|
return helmpath;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findHelm(rootFolder: string): string {
|
||||||
|
fs.chmodSync(rootFolder, '777');
|
||||||
|
var filelist: string[] = [];
|
||||||
|
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
|
||||||
|
if (!filelist || filelist.length == 0) {
|
||||||
|
throw new Error(util.format("Helm executable not found in path", rootFolder));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return filelist[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export 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;
|
||||||
|
};
|
||||||
|
|
||||||
run().catch(core.setFailed);
|
run().catch(core.setFailed);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue