mirror of
https://github.com/Azure/setup-helm.git
synced 2025-11-07 13:06:56 +00:00
Latest getLatestHelmVersion iteration
This commit is contained in:
parent
363e4253a0
commit
f1588f7abf
4 changed files with 7544 additions and 55 deletions
|
|
@ -22,31 +22,31 @@ describe('run.ts', () => {
|
|||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Linux');
|
||||
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.7.2-linux-amd64.zip'
|
||||
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.8.0-linux-amd64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.7.2')).toBe(kubectlLinuxUrl);
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
||||
const kubectlDarwinUrl = 'https://get.helm.sh/helm-v3.7.2-darwin-amd64.zip'
|
||||
const kubectlDarwinUrl = 'https://get.helm.sh/helm-v3.8.0-darwin-amd64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.7.2')).toBe(kubectlDarwinUrl);
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
|
||||
const kubectlWindowsUrl = 'https://get.helm.sh/helm-v3.7.2-windows-amd64.zip'
|
||||
expect(run.getHelmDownloadURL('v3.7.2')).toBe(kubectlWindowsUrl);
|
||||
const kubectlWindowsUrl = 'https://get.helm.sh/helm-v3.8.0-windows-amd64.zip'
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlWindowsUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
|
||||
try{
|
||||
expect(run.getLatestHelmVersion()).toBe("v3.7.2");
|
||||
expect(run.getLatestHelmVersion()).toBe("v3.8.0");
|
||||
} catch (e){
|
||||
return e;
|
||||
}
|
||||
|
|
@ -76,9 +76,9 @@ describe('run.ts', () => {
|
|||
jest.spyOn(toolCache, 'downloadTool').mockRejectedValue('Unable to download');
|
||||
jest.spyOn(core, 'warning').mockImplementation();
|
||||
|
||||
expect(await run.getStableHelmVersion()).toBe('v3.7.2');
|
||||
expect(await run.getStableHelmVersion()).toBe('v3.8.0');
|
||||
expect(toolCache.downloadTool).toBeCalled();
|
||||
expect(core.warning).toBeCalledWith("Cannot get the latest Helm info from https://api.github.com/repos/helm/helm/releases. Error Unable to download. Using default Helm version v3.7.2.");
|
||||
expect(core.warning).toBeCalledWith("Cannot get the latest Helm info from https://api.github.com/repos/helm/helm/releases. Error Unable to download. Using default Helm version v3.8.0.");
|
||||
});
|
||||
|
||||
test('walkSync() - return path to the all files matching fileToFind in dir', () => {
|
||||
|
|
|
|||
32
lib/run.js
32
lib/run.js
|
|
@ -18,11 +18,10 @@ const path = require("path");
|
|||
const util = require("util");
|
||||
const fs = require("fs");
|
||||
const semver = require("semver");
|
||||
const exec = require("@actions/exec");
|
||||
const toolCache = require("@actions/tool-cache");
|
||||
const core = require("@actions/core");
|
||||
const helmToolName = 'helm';
|
||||
const stableHelmVersion = 'v3.7.2';
|
||||
const stableHelmVersion = 'v3.8.0';
|
||||
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
|
||||
function getExecutableExtension() {
|
||||
if (os.type().match(/^Win/)) {
|
||||
|
|
@ -113,27 +112,20 @@ function downloadHelm(version) {
|
|||
});
|
||||
}
|
||||
exports.downloadHelm = downloadHelm;
|
||||
// getLatestHelmVersion uses cURL and regex to scrape the latest version
|
||||
function getLatestHelmVersion() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
console.log("Test");
|
||||
const command = `curl -Ls https://api.github.com/repos/helm/helm/releases | grep 'v3.[0-9]*.[0-9]*' | sed -E 's/ .*\/helm\/helm\/releases\/tag\/tag\/(v[0-9\.]+)".*/\\1/g' | head -1 | sed -E 's/.*tag\///' | sed -E 's/".*//'`;
|
||||
let latestHelm = "";
|
||||
let latestHelmErr = "";
|
||||
const options = {};
|
||||
options.listeners = {
|
||||
stdout: (data) => {
|
||||
latestHelm += data.toString();
|
||||
},
|
||||
stderr: (data) => {
|
||||
latestHelmErr += data.toString();
|
||||
let helmJSONPath = yield toolCache.downloadTool("https://api.github.com/repos/helm/helm/releases");
|
||||
let versions;
|
||||
const helmJSONArray = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'));
|
||||
for (const i in helmJSONArray) {
|
||||
versions.push(helmJSONArray[i]["tag_name"]);
|
||||
}
|
||||
for (const v in versions) {
|
||||
if (isValidVersion(v)) {
|
||||
return v;
|
||||
}
|
||||
};
|
||||
yield exec.exec(command, [], options);
|
||||
console.log("latestHelm");
|
||||
if (latestHelmErr !== "" || !isValidVersion(latestHelm))
|
||||
return getStableHelmVersion();
|
||||
return latestHelm;
|
||||
}
|
||||
return stableHelmVersion;
|
||||
});
|
||||
}
|
||||
exports.getLatestHelmVersion = getLatestHelmVersion;
|
||||
|
|
|
|||
7510
package-lock.json
generated
7510
package-lock.json
generated
File diff suppressed because it is too large
Load diff
39
src/run.ts
39
src/run.ts
|
|
@ -8,13 +8,11 @@ import * as util from 'util';
|
|||
import * as fs from 'fs';
|
||||
import * as semver from 'semver';
|
||||
|
||||
import * as exec from '@actions/exec';
|
||||
import { ExecOptions } from '@actions/exec/lib/interfaces';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
const helmToolName = 'helm';
|
||||
const stableHelmVersion = 'v3.7.2';
|
||||
const stableHelmVersion = 'v3.8.0';
|
||||
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
|
||||
|
||||
export function getExecutableExtension(): string {
|
||||
|
|
@ -105,28 +103,23 @@ export async function downloadHelm(version: string): Promise<string> {
|
|||
return helmpath;
|
||||
}
|
||||
|
||||
// getLatestHelmVersion uses cURL and regex to scrape the latest version
|
||||
export async function getLatestHelmVersion(): Promise<string>{
|
||||
console.log("Test");
|
||||
const command:string = `curl -Ls https://api.github.com/repos/helm/helm/releases | grep 'v3.[0-9]*.[0-9]*' | sed -E 's/ .*\/helm\/helm\/releases\/tag\/tag\/(v[0-9\.]+)".*/\\1/g' | head -1 | sed -E 's/.*tag\///' | sed -E 's/".*//'`;
|
||||
let latestHelm: string = "";
|
||||
let latestHelmErr: string = "";
|
||||
|
||||
const options:ExecOptions = {};
|
||||
export async function getLatestHelmVersion(): Promise<string> {
|
||||
let helmJSONPath:string = await toolCache.downloadTool("https://api.github.com/repos/helm/helm/releases");
|
||||
let versions:Array<string>;
|
||||
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
latestHelm += data.toString();
|
||||
},
|
||||
stderr: (data: Buffer) => {
|
||||
latestHelmErr += data.toString();
|
||||
const helmJSONArray:JSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'))
|
||||
|
||||
for(const i in helmJSONArray){
|
||||
versions.push(helmJSONArray[i]["tag_name"]);
|
||||
}
|
||||
|
||||
for(const v in versions){
|
||||
if(isValidVersion(v)){
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
await exec.exec(command, [], options);
|
||||
console.log("latestHelm")
|
||||
if(latestHelmErr !== "" || !isValidVersion(latestHelm)) return getStableHelmVersion();
|
||||
return latestHelm;
|
||||
}
|
||||
|
||||
return stableHelmVersion;
|
||||
}
|
||||
|
||||
// isValidVersion checks if verison matches the specified type and is a stable release
|
||||
|
|
|
|||
Loading…
Reference in a new issue