support only v3 and switch away from github token
This commit is contained in:
33
.github/workflows/TriggerIntegrationTests.sh
vendored
33
.github/workflows/TriggerIntegrationTests.sh
vendored
@ -1,33 +0,0 @@
|
|||||||
token=$1
|
|
||||||
commit=$2
|
|
||||||
repository=$3
|
|
||||||
prNumber=$4
|
|
||||||
frombranch=$5
|
|
||||||
tobranch=$6
|
|
||||||
patUser=$7
|
|
||||||
|
|
||||||
getPayLoad() {
|
|
||||||
cat <<EOF
|
|
||||||
{
|
|
||||||
"event_type": "SetupHelmActionPR",
|
|
||||||
"client_payload":
|
|
||||||
{
|
|
||||||
"action": "SetupHelm",
|
|
||||||
"commit": "$commit",
|
|
||||||
"repository": "$repository",
|
|
||||||
"prNumber": "$prNumber",
|
|
||||||
"tobranch": "$tobranch",
|
|
||||||
"frombranch": "$frombranch"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
response=$(curl -u $patUser:$token -X POST https://api.github.com/repos/Azure/azure-actions-integration-tests/dispatches --data "$(getPayLoad)")
|
|
||||||
|
|
||||||
if [ "$response" == "" ]; then
|
|
||||||
echo "Integration tests triggered successfully"
|
|
||||||
else
|
|
||||||
echo "Triggering integration tests failed with: '$response'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
56
.github/workflows/integration-tests.yml
vendored
56
.github/workflows/integration-tests.yml
vendored
@ -8,12 +8,58 @@ jobs:
|
|||||||
trigger-integration-tests:
|
trigger-integration-tests:
|
||||||
name: Trigger Integration tests
|
name: Trigger Integration tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
HELM_3_8_0: "v3.8.0"
|
||||||
|
HELM_3_7_2: "v3.7.2"
|
||||||
|
HELM_3_5_0: "v3.5.0"
|
||||||
|
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
- name: npm install and build
|
||||||
path: IntegrationTests
|
id: action-npm-build
|
||||||
|
|
||||||
- name: Trigger Test run
|
|
||||||
run: |
|
run: |
|
||||||
bash ./IntegrationTests/.github/workflows/TriggerIntegrationTests.sh ${{ secrets.L2_REPO_TOKEN }} ${{ github.event.pull_request.head.sha }} ${{ github.repository }} ${{ github.event.pull_request.number }} ${{ github.event.pull_request.head.ref }} ${{ github.event.pull_request.base.ref }} ${{ secrets.L2_REPO_USER }}
|
echo $PR_BASE_REF
|
||||||
|
if [[ $PR_BASE_REF != releases/* ]]; then
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
fi
|
||||||
|
- name: Setup helm
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: ${{ env.HELM_3_8_0 }}
|
||||||
|
- name: Validate helm 3.8.0
|
||||||
|
run: |
|
||||||
|
if [[ $(helm version) != *$HELM_3_8_0* ]]; then
|
||||||
|
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.8.0"
|
||||||
|
echo "HELM VERSION OUTPUT: $(helm version)"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "HELM VERSION $HELM_3_8_0 INSTALLED SUCCESSFULLY"
|
||||||
|
fi
|
||||||
|
- name: Setup helm 3.7.2
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: ${{ env.HELM_3_7_2 }}
|
||||||
|
- name: Validate 3.7.2
|
||||||
|
run: |
|
||||||
|
if [[ $(helm version) != *$HELM_3_7_2* ]]; then
|
||||||
|
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.7.2"
|
||||||
|
echo "HELM VERSION OUTPUT: $(helm version)"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "HELM VERSION $HELM_3_7_2 INSTALLED SUCCESSFULLY"
|
||||||
|
fi
|
||||||
|
- name: Setup helm 3.5.0
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
version: ${{ env.HELM_3_5_0 }}
|
||||||
|
- name: Validate 3.5.0
|
||||||
|
run: |
|
||||||
|
if [[ $(helm version) != *$HELM_3_5_0* ]]; then
|
||||||
|
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.5.0"
|
||||||
|
echo "HELM VERSION OUTPUT: $(helm version)"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "HELM VERSION $HELM_3_5_0 INSTALLED SUCCESSFULLY"
|
||||||
|
fi
|
@ -22,55 +22,34 @@ describe('run.ts', () => {
|
|||||||
|
|
||||||
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
|
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Linux');
|
jest.spyOn(os, 'type').mockReturnValue('Linux');
|
||||||
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.2.1-linux-amd64.zip'
|
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.8.0-linux-amd64.zip'
|
||||||
|
|
||||||
expect(run.getHelmDownloadURL('v3.2.1')).toBe(kubectlLinuxUrl);
|
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxUrl);
|
||||||
expect(os.type).toBeCalled();
|
expect(os.type).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
|
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
||||||
const kubectlDarwinUrl = 'https://get.helm.sh/helm-v3.2.1-darwin-amd64.zip'
|
const kubectlDarwinUrl = 'https://get.helm.sh/helm-v3.8.0-darwin-amd64.zip'
|
||||||
|
|
||||||
expect(run.getHelmDownloadURL('v3.2.1')).toBe(kubectlDarwinUrl);
|
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinUrl);
|
||||||
expect(os.type).toBeCalled();
|
expect(os.type).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
|
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||||
|
|
||||||
const kubectlWindowsUrl = 'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
|
const kubectlWindowsUrl = 'https://get.helm.sh/helm-v3.8.0-windows-amd64.zip'
|
||||||
expect(run.getHelmDownloadURL('v3.2.1')).toBe(kubectlWindowsUrl);
|
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlWindowsUrl);
|
||||||
expect(os.type).toBeCalled();
|
expect(os.type).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getStableHelmVersion() - download stable version file, read version and return it', async () => {
|
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
|
||||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');
|
try{
|
||||||
const response = JSON.stringify(
|
expect(await run.getLatestHelmVersion()).toBe("v3.8.0");
|
||||||
[
|
} catch (e){
|
||||||
{
|
return e;
|
||||||
'tag_name': 'v4.0.0'
|
|
||||||
}, {
|
|
||||||
'tag_name': 'v3.0.0'
|
|
||||||
}, {
|
|
||||||
'tag_name': 'v2.0.0'
|
|
||||||
}
|
}
|
||||||
]
|
|
||||||
);
|
|
||||||
jest.spyOn(fs, 'readFileSync').mockReturnValue(response);
|
|
||||||
|
|
||||||
expect(await run.getStableHelmVersion()).toBe('v4.0.0');
|
|
||||||
expect(toolCache.downloadTool).toBeCalled();
|
|
||||||
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('getStableHelmVersion() - return default version if error occurs while getting latest version', async () => {
|
|
||||||
jest.spyOn(toolCache, 'downloadTool').mockRejectedValue('Unable to download');
|
|
||||||
jest.spyOn(core, 'warning').mockImplementation();
|
|
||||||
|
|
||||||
expect(await run.getStableHelmVersion()).toBe('v3.2.1');
|
|
||||||
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.2.1.");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('walkSync() - return path to the all files matching fileToFind in dir', () => {
|
test('walkSync() - return path to the all files matching fileToFind in dir', () => {
|
||||||
@ -146,7 +125,7 @@ describe('run.ts', () => {
|
|||||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(await run.downloadHelm(null)).toBe(path.join('pathToCachedDir', 'helm.exe'));
|
expect(await run.downloadHelm("v4.0.0")).toBe(path.join('pathToCachedDir', 'helm.exe'));
|
||||||
expect(toolCache.find).toBeCalledWith('helm', 'v4.0.0');
|
expect(toolCache.find).toBeCalledWith('helm', 'v4.0.0');
|
||||||
expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v4.0.0-windows-amd64.zip');
|
expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v4.0.0-windows-amd64.zip');
|
||||||
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777');
|
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777');
|
||||||
|
292
lib/run.js
292
lib/run.js
@ -2,25 +2,6 @@
|
|||||||
// Copyright (c) Microsoft Corporation.
|
// 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) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
||||||
}) : (function(o, m, k, k2) {
|
|
||||||
if (k2 === undefined) k2 = k;
|
|
||||||
o[k2] = m[k];
|
|
||||||
}));
|
|
||||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
||||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
||||||
}) : function(o, v) {
|
|
||||||
o["default"] = v;
|
|
||||||
});
|
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
|
||||||
if (mod && mod.__esModule) return mod;
|
|
||||||
var result = {};
|
|
||||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
@ -31,179 +12,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getStableHelmVersion = void 0;
|
exports.walkSync = exports.findHelm = exports.downloadHelm = exports.getHelmDownloadURL = exports.getExecutableExtension = exports.getLatestHelmVersion = exports.run = void 0;
|
||||||
const os = __importStar(require("os"));
|
const os = require("os");
|
||||||
const path = __importStar(require("path"));
|
const path = require("path");
|
||||||
const util = __importStar(require("util"));
|
const util = require("util");
|
||||||
const fs = __importStar(require("fs"));
|
const fs = require("fs");
|
||||||
const semver = __importStar(require("semver"));
|
const toolCache = require("@actions/tool-cache");
|
||||||
const toolCache = __importStar(require("@actions/tool-cache"));
|
const core = require("@actions/core");
|
||||||
const core = __importStar(require("@actions/core"));
|
|
||||||
const graphql_1 = require("@octokit/graphql");
|
|
||||||
const helmToolName = 'helm';
|
const helmToolName = 'helm';
|
||||||
const stableHelmVersion = 'v3.2.1';
|
const stableHelmVersion = 'v3.8.0';
|
||||||
const stableHelm3Version = 'v3.5.3';
|
|
||||||
const stableHelm2Version = 'v2.17.0';
|
|
||||||
const LATEST_HELM2_VERSION = '2.*';
|
|
||||||
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() {
|
|
||||||
if (os.type().match(/^Win/)) {
|
|
||||||
return '.exe';
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
function getHelmDownloadURL(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 'Windows_NT':
|
|
||||||
default:
|
|
||||||
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function getStableHelmVersion() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
try {
|
|
||||||
const downloadPath = yield toolCache.downloadTool(helmAllReleasesUrl);
|
|
||||||
const responseArray = JSON.parse(fs.readFileSync(downloadPath, 'utf8').toString().trim());
|
|
||||||
let latestHelmVersion = semver.clean(stableHelmVersion);
|
|
||||||
responseArray.forEach(response => {
|
|
||||||
if (response && response.tag_name) {
|
|
||||||
let currentHelmVerison = semver.clean(response.tag_name.toString());
|
|
||||||
if (currentHelmVerison) {
|
|
||||||
if (currentHelmVerison.toString().indexOf('rc') == -1 && semver.gt(currentHelmVerison, latestHelmVersion)) {
|
|
||||||
//If current helm version is not a pre release and is greater than latest helm version
|
|
||||||
latestHelmVersion = currentHelmVerison;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
latestHelmVersion = "v" + latestHelmVersion;
|
|
||||||
return latestHelmVersion;
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
core.warning(util.format("Cannot get the latest Helm info from %s. Error %s. Using default Helm version %s.", helmAllReleasesUrl, error, stableHelmVersion));
|
|
||||||
}
|
|
||||||
return stableHelmVersion;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
exports.getStableHelmVersion = getStableHelmVersion;
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
function downloadHelm(version) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
if (!version) {
|
|
||||||
version = yield getLatestHelmVersionFor("v3");
|
|
||||||
}
|
|
||||||
let cachedToolpath = toolCache.find(helmToolName, version);
|
|
||||||
if (!cachedToolpath) {
|
|
||||||
let helmDownloadPath;
|
|
||||||
try {
|
|
||||||
helmDownloadPath = yield 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 = yield toolCache.extractZip(helmDownloadPath);
|
|
||||||
cachedToolpath = yield 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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function getLatestHelmVersionFor(type) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const token = core.getInput('token', { 'required': true });
|
|
||||||
try {
|
|
||||||
const { repository } = yield graphql_1.graphql(`{
|
|
||||||
repository(name: "helm", owner: "helm") {
|
|
||||||
releases(last: 100) {
|
|
||||||
nodes {
|
|
||||||
tagName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`, {
|
|
||||||
headers: {
|
|
||||||
authorization: `token ${token}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const releases = repository.releases.nodes.reverse();
|
|
||||||
let latestValidRelease = releases.find(release => isValidVersion(release.tagName, type));
|
|
||||||
if (latestValidRelease)
|
|
||||||
return latestValidRelease.tagName;
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
core.warning(util.format("Error while fetching the latest Helm %s release. Error: %s. Using default Helm version %s.", type, err.toString(), getStableHelmVersionFor(type)));
|
|
||||||
return getStableHelmVersionFor(type);
|
|
||||||
}
|
|
||||||
core.warning(util.format("Could not find stable release for Helm %s. Using default Helm version %s.", type, getStableHelmVersionFor(type)));
|
|
||||||
return getStableHelmVersionFor(type);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function getStableHelmVersionFor(type) {
|
|
||||||
return type === "v2" ? stableHelm2Version : stableHelm3Version;
|
|
||||||
}
|
|
||||||
// isValidVersion checks if verison matches the specified type and is a stable release
|
|
||||||
function isValidVersion(version, type) {
|
|
||||||
if (!version.toLocaleLowerCase().startsWith(type))
|
|
||||||
return false;
|
|
||||||
return version.indexOf('rc') == -1;
|
|
||||||
}
|
|
||||||
function findHelm(rootFolder) {
|
|
||||||
fs.chmodSync(rootFolder, '777');
|
|
||||||
var filelist = [];
|
|
||||||
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
|
|
||||||
if (!filelist) {
|
|
||||||
throw new Error(util.format("Helm executable not found in path ", rootFolder));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return filelist[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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['HELM_INSTALLER_LEGACY_VERSIONING'] == 'true') {
|
|
||||||
if (version.toLocaleLowerCase() === 'latest') {
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
version = yield getStableHelmVersion();
|
version = yield getLatestHelmVersion();
|
||||||
}
|
|
||||||
else if (!version.toLocaleLowerCase().startsWith('v')) {
|
|
||||||
version = 'v' + version;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
core.debug(util.format("Downloading %s", version));
|
core.debug(util.format("Downloading %s", version));
|
||||||
let cachedPath = yield downloadHelm(version);
|
let cachedPath = yield downloadHelm(version);
|
||||||
@ -219,4 +42,101 @@ function run() {
|
|||||||
core.setOutput('helm-path', 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() {
|
||||||
|
if (os.type().match(/^Win/)) {
|
||||||
|
return '.exe';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
exports.getExecutableExtension = getExecutableExtension;
|
||||||
|
function getHelmDownloadURL(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 'Windows_NT':
|
||||||
|
default:
|
||||||
|
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.getHelmDownloadURL = getHelmDownloadURL;
|
||||||
|
function downloadHelm(version) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let cachedToolpath = toolCache.find(helmToolName, version);
|
||||||
|
if (!cachedToolpath) {
|
||||||
|
let helmDownloadPath;
|
||||||
|
try {
|
||||||
|
helmDownloadPath = yield 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 = yield toolCache.extractZip(helmDownloadPath);
|
||||||
|
cachedToolpath = yield 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.downloadHelm = downloadHelm;
|
||||||
|
function findHelm(rootFolder) {
|
||||||
|
fs.chmodSync(rootFolder, '777');
|
||||||
|
var filelist = [];
|
||||||
|
exports.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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.findHelm = findHelm;
|
||||||
|
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;
|
||||||
|
};
|
||||||
run().catch(core.setFailed);
|
run().catch(core.setFailed);
|
||||||
|
11645
package-lock.json
generated
11645
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
189
src/run.ts
189
src/run.ts
@ -6,20 +6,64 @@ 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 semver from 'semver';
|
|
||||||
|
|
||||||
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';
|
||||||
import { graphql } from '@octokit/graphql';
|
|
||||||
|
|
||||||
const helmToolName = 'helm';
|
const helmToolName = 'helm';
|
||||||
const stableHelmVersion = 'v3.2.1';
|
const stableHelmVersion = 'v3.8.0';
|
||||||
const stableHelm3Version = 'v3.5.3';
|
|
||||||
const stableHelm2Version = 'v2.17.0';
|
|
||||||
const LATEST_HELM2_VERSION = '2.*';
|
|
||||||
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';
|
||||||
|
|
||||||
|
export async function run() {
|
||||||
|
let version = core.getInput('version', { 'required': true });
|
||||||
|
|
||||||
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
|
version = await getLatestHelmVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
core.debug(util.format("Downloading %s", version));
|
||||||
|
let cachedPath = await downloadHelm(version);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
||||||
|
core.addPath(path.dirname(cachedPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
//do nothing, set as output variable
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`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.
|
||||||
|
// 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 {
|
export function getExecutableExtension(): string {
|
||||||
if (os.type().match(/^Win/)) {
|
if (os.type().match(/^Win/)) {
|
||||||
return '.exe';
|
return '.exe';
|
||||||
@ -41,50 +85,7 @@ export function getHelmDownloadURL(version: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStableHelmVersion(): Promise<string> {
|
|
||||||
try {
|
|
||||||
const downloadPath = await toolCache.downloadTool(helmAllReleasesUrl);
|
|
||||||
const responseArray = JSON.parse(fs.readFileSync(downloadPath, 'utf8').toString().trim());
|
|
||||||
let latestHelmVersion = semver.clean(stableHelmVersion);
|
|
||||||
responseArray.forEach(response => {
|
|
||||||
if (response && response.tag_name) {
|
|
||||||
let currentHelmVerison = semver.clean(response.tag_name.toString());
|
|
||||||
if (currentHelmVerison) {
|
|
||||||
if (currentHelmVerison.toString().indexOf('rc') == -1 && semver.gt(currentHelmVerison, latestHelmVersion)) {
|
|
||||||
//If current helm version is not a pre release and is greater than latest helm version
|
|
||||||
latestHelmVersion = currentHelmVerison;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
latestHelmVersion = "v" + latestHelmVersion;
|
|
||||||
return latestHelmVersion;
|
|
||||||
} catch (error) {
|
|
||||||
core.warning(util.format("Cannot get the latest Helm info from %s. Error %s. Using default Helm version %s.", helmAllReleasesUrl, error, stableHelmVersion));
|
|
||||||
}
|
|
||||||
|
|
||||||
return stableHelmVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
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> {
|
export async function downloadHelm(version: string): Promise<string> {
|
||||||
if (!version) { version = await getStableHelmVersion(); }
|
|
||||||
let cachedToolpath = toolCache.find(helmToolName, version);
|
let cachedToolpath = toolCache.find(helmToolName, version);
|
||||||
if (!cachedToolpath) {
|
if (!cachedToolpath) {
|
||||||
let helmDownloadPath;
|
let helmDownloadPath;
|
||||||
@ -108,49 +109,6 @@ export async function downloadHelm(version: string): Promise<string> {
|
|||||||
return helmpath;
|
return helmpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLatestHelmVersionFor(type: string): Promise<string> {
|
|
||||||
const token = core.getInput('token', { 'required': true });
|
|
||||||
try {
|
|
||||||
const { repository } = await graphql(
|
|
||||||
`{
|
|
||||||
repository(name: "helm", owner: "helm") {
|
|
||||||
releases(last: 100) {
|
|
||||||
nodes {
|
|
||||||
tagName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
authorization: `token ${token}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const releases = repository.releases.nodes.reverse();
|
|
||||||
let latestValidRelease = releases.find(release => isValidVersion(release.tagName, type));
|
|
||||||
if (latestValidRelease)
|
|
||||||
return latestValidRelease.tagName;
|
|
||||||
} catch (err) {
|
|
||||||
core.warning(util.format("Error while fetching the latest Helm %s release. Error: %s. Using default Helm version %s.", type, err.toString(), getStableHelmVersionFor(type)));
|
|
||||||
return getStableHelmVersionFor(type);
|
|
||||||
}
|
|
||||||
core.warning(util.format("Could not find stable release for Helm %s. Using default Helm version %s.", type, getStableHelmVersionFor(type)));
|
|
||||||
return getStableHelmVersionFor(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getStableHelmVersionFor(type: string) {
|
|
||||||
return type === "v2" ? stableHelm2Version : stableHelm3Version;
|
|
||||||
}
|
|
||||||
|
|
||||||
// isValidVersion checks if verison matches the specified type and is a stable release
|
|
||||||
function isValidVersion(version: string, type: string): boolean {
|
|
||||||
if (!version.toLocaleLowerCase().startsWith(type))
|
|
||||||
return false;
|
|
||||||
return version.indexOf('rc') == -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
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[] = [];
|
||||||
@ -163,40 +121,21 @@ export function findHelm(rootFolder: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function run() {
|
export var walkSync = function (dir, filelist, fileToFind) {
|
||||||
let version = core.getInput('version', { 'required': true });
|
var files = fs.readdirSync(dir);
|
||||||
|
filelist = filelist || [];
|
||||||
if (process.env['HELM_INSTALLER_LEGACY_VERSIONING'] == 'true') {
|
files.forEach(function (file) {
|
||||||
if (version.toLocaleLowerCase() === 'latest') {
|
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||||
version = await getStableHelmVersion();
|
filelist = walkSync(path.join(dir, file), filelist, fileToFind);
|
||||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
|
||||||
version = 'v' + version;
|
|
||||||
}
|
}
|
||||||
} else {
|
else {
|
||||||
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
core.debug(file);
|
||||||
version = await getLatestHelmVersionFor("v3");
|
if (file == fileToFind) {
|
||||||
} else if (version === LATEST_HELM2_VERSION) {
|
filelist.push(path.join(dir, file));
|
||||||
version = await getLatestHelmVersionFor("v2");
|
|
||||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
|
||||||
version = 'v' + version;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
core.debug(util.format("Downloading %s", version));
|
return filelist;
|
||||||
let cachedPath = await downloadHelm(version);
|
};
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
|
||||||
core.addPath(path.dirname(cachedPath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
//do nothing, set as output variable
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`);
|
|
||||||
core.setOutput('helm-path', cachedPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
run().catch(core.setFailed);
|
run().catch(core.setFailed);
|
||||||
|
Reference in New Issue
Block a user