mirror of
https://github.com/Azure/setup-helm.git
synced 2025-07-16 02:30:36 +00:00
Compare commits
14 Commits
v1.1
...
jysin/test
Author | SHA1 | Date | |
---|---|---|---|
9f1aa14c82 | |||
62aeada586 | |||
edc063ca5f | |||
e77e49c8f8 | |||
d315e938e1 | |||
509333604f | |||
91b7d21636 | |||
b1c4524a5f | |||
f404b8932e | |||
1de6b70ec6 | |||
d0d63812ab | |||
87a2cd59a0 | |||
fe2c706cad | |||
11c996f4c7 |
33
.github/workflows/TriggerIntegrationTests.sh
vendored
Normal file
33
.github/workflows/TriggerIntegrationTests.sh
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
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
|
19
.github/workflows/integration-tests.yml
vendored
Normal file
19
.github/workflows/integration-tests.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
name: "Trigger Integration tests"
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- 'releases/*'
|
||||
jobs:
|
||||
trigger-integration-tests:
|
||||
name: Trigger Integration tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: IntegrationTests
|
||||
|
||||
- name: Trigger Test 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 }}
|
21
.github/workflows/unit-tests.yml
vendored
Normal file
21
.github/workflows/unit-tests.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: "Run unit tests."
|
||||
on: # rebuild any PRs and main branch changes
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- 'releases/*'
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- 'releases/*'
|
||||
|
||||
jobs:
|
||||
build: # make sure build/ci works properly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Run L0 tests.
|
||||
run: |
|
||||
npm install
|
||||
npm test
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -59,3 +59,6 @@ typings/
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
node_modules
|
||||
coverage
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Setup Helm
|
||||
#### Install a specific version of helm binary on the runner.
|
||||
|
||||
Acceptable values are latest or any semantic version string like 1.15.0. Use this action in workflow to define which version of helm will be used.
|
||||
Acceptable values are latest or any semantic version string like v2.16.7 Use this action in workflow to define which version of helm will be used.
|
||||
|
||||
```yaml
|
||||
- uses: azure/setup-helm@v1
|
||||
@ -9,6 +9,8 @@ Acceptable values are latest or any semantic version string like 1.15.0. Use thi
|
||||
version: '<version>' # default is latest stable
|
||||
id: install
|
||||
```
|
||||
|
||||
The cached helm binary path is prepended to the PATH environment variable as well as stored in the helm-path output variable.
|
||||
Refer to the action metadata file for details about all the inputs https://github.com/Azure/setup-helm/blob/master/action.yml
|
||||
|
||||
# Contributing
|
||||
|
195
__tests__/run.test.ts
Normal file
195
__tests__/run.test.ts
Normal file
@ -0,0 +1,195 @@
|
||||
import * as run from '../src/run'
|
||||
import * as os from 'os';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
describe('run.ts', () => {
|
||||
test('getExecutableExtension() - return .exe when os is Windows', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
|
||||
expect(run.getExecutableExtension()).toBe('.exe');
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getExecutableExtension() - return empty string for non-windows OS', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
||||
|
||||
expect(run.getExecutableExtension()).toBe('');
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Linux');
|
||||
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.2.1-linux-amd64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.2.1')).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.2.1-darwin-amd64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.2.1')).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.2.1-windows-amd64.zip'
|
||||
expect(run.getHelmDownloadURL('v3.2.1')).toBe(kubectlWindowsUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getStableHelmVersion() - download stable version file, read version and return it', async () => {
|
||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');
|
||||
const response = JSON.stringify(
|
||||
[
|
||||
{
|
||||
'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', () => {
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return ['file1' as unknown as fs.Dirent, 'file2' as unknown as fs.Dirent, 'folder1' as unknown as fs.Dirent, 'folder2' as unknown as fs.Dirent];
|
||||
if (file == path.join('mainFolder', 'folder1')) return ['file11' as unknown as fs.Dirent, 'file12' as unknown as fs.Dirent];
|
||||
if (file == path.join('mainFolder', 'folder2')) return ['file21' as unknown as fs.Dirent, 'file22' as unknown as fs.Dirent];
|
||||
});
|
||||
jest.spyOn(core, 'debug').mockImplementation();
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory = (file as string).toLowerCase().indexOf('file') == -1 ? true: false
|
||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||
});
|
||||
|
||||
expect(run.walkSync('mainFolder', null, 'file21')).toEqual([path.join('mainFolder', 'folder2', 'file21')]);
|
||||
expect(fs.readdirSync).toBeCalledTimes(3);
|
||||
expect(fs.statSync).toBeCalledTimes(8);
|
||||
});
|
||||
|
||||
test('walkSync() - return empty array if no file with name fileToFind exists', () => {
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return ['file1' as unknown as fs.Dirent, 'file2' as unknown as fs.Dirent, 'folder1' as unknown as fs.Dirent, 'folder2' as unknown as fs.Dirent];
|
||||
if (file == path.join('mainFolder', 'folder1')) return ['file11' as unknown as fs.Dirent, 'file12' as unknown as fs.Dirent];
|
||||
if (file == path.join('mainFolder', 'folder2')) return ['file21' as unknown as fs.Dirent, 'file22' as unknown as fs.Dirent];
|
||||
});
|
||||
jest.spyOn(core, 'debug').mockImplementation();
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory = (file as string).toLowerCase().indexOf('file') == -1 ? true: false
|
||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||
});
|
||||
|
||||
expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([]);
|
||||
expect(fs.readdirSync).toBeCalledTimes(3);
|
||||
expect(fs.statSync).toBeCalledTimes(8);
|
||||
});
|
||||
|
||||
test('findHelm() - change access permissions and find the helm in given directory', () => {
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return ['helm.exe' as unknown as fs.Dirent];
|
||||
});
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory = (file as string).indexOf('folder') == -1 ? false: true
|
||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||
});
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
|
||||
expect(run.findHelm('mainFolder')).toBe(path.join('mainFolder', 'helm.exe'));
|
||||
});
|
||||
|
||||
test('findHelm() - throw error if executable not found', () => {
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return [];
|
||||
});
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => { return { isDirectory: () => true } as fs.Stats});
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
expect(() => run.findHelm('mainFolder')).toThrow('Helm executable not found in path mainFolder');
|
||||
});
|
||||
|
||||
test('downloadHelm() - download helm and return path to it', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');
|
||||
const response = JSON.stringify([{'tag_name': 'v4.0.0'}]);
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue(response);
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});
|
||||
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('pathToUnzippedHelm');
|
||||
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir');
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => ['helm.exe' as unknown as fs.Dirent]);
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory = (file as string).indexOf('folder') == -1 ? false: true
|
||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||
});
|
||||
|
||||
expect(await run.downloadHelm(null)).toBe(path.join('pathToCachedDir', 'helm.exe'));
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v4.0.0');
|
||||
expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v4.0.0-windows-amd64.zip');
|
||||
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777');
|
||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool');
|
||||
expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedDir', 'helm.exe'), '777');
|
||||
});
|
||||
|
||||
test('downloadHelm() - throw error if unable to download', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => { throw 'Unable to download'});
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
|
||||
await expect(run.downloadHelm('v3.2.1')).rejects.toThrow('Failed to download Helm from location https://get.helm.sh/helm-v3.2.1-windows-amd64.zip');
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1');
|
||||
expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v3.2.1-windows-amd64.zip');
|
||||
});
|
||||
|
||||
test('downloadHelm() - return path to helm tool with same version from toolCache', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});
|
||||
|
||||
expect(await run.downloadHelm('v3.2.1')).toBe(path.join('pathToCachedDir', 'helm.exe'));
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1');
|
||||
expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedDir', 'helm.exe'), '777');
|
||||
});
|
||||
|
||||
test('downloadHelm() - throw error is helm is not found in path', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation();
|
||||
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('pathToUnzippedHelm');
|
||||
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir');
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => []);
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory = (file as string).indexOf('folder') == -1 ? false: true
|
||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||
});
|
||||
|
||||
await expect(run.downloadHelm('v3.2.1')).rejects.toThrow('Helm executable not found in path pathToCachedDir');
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1');
|
||||
expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v3.2.1-windows-amd64.zip');
|
||||
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777');
|
||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool');
|
||||
});
|
||||
});
|
@ -1,10 +1,14 @@
|
||||
name: 'Helm tool installer'
|
||||
description: 'Install a specific version of helm binary. Acceptable values are latest or any semantic version string like 1.15.0'
|
||||
inputs:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version of helm'
|
||||
required: true
|
||||
default: 'latest'
|
||||
token:
|
||||
description: 'Github token'
|
||||
default: ${{ github.token }}
|
||||
required: true
|
||||
outputs:
|
||||
helm-path:
|
||||
description: 'Path to the cached helm binary'
|
||||
|
18
jest.config.js
Normal file
18
jest.config.js
Normal file
@ -0,0 +1,18 @@
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true,
|
||||
coverageThreshold: {
|
||||
"global": {
|
||||
"branches": 0,
|
||||
"functions": 14,
|
||||
"lines": 27,
|
||||
"statements": 27
|
||||
}
|
||||
}
|
||||
}
|
146
lib/run.js
146
lib/run.js
@ -1,6 +1,26 @@
|
||||
"use strict";
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// 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) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
@ -10,23 +30,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getStableHelmVersion = void 0;
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
const util = __importStar(require("util"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const toolCache = __importStar(require("../node_modules/@actions/tool-cache"));
|
||||
const core = __importStar(require("../node_modules/@actions/core"));
|
||||
const semver = __importStar(require("semver"));
|
||||
const toolCache = __importStar(require("@actions/tool-cache"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const graphql_1 = require("@octokit/graphql");
|
||||
const helmToolName = 'helm';
|
||||
const stableHelmVersion = 'v2.14.1';
|
||||
const helmLatestReleaseUrl = 'https://api.github.com/repos/helm/helm/releases/latest';
|
||||
const stableHelmVersion = 'v3.2.1';
|
||||
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';
|
||||
function getExecutableExtension() {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
@ -46,19 +66,31 @@ function getHelmDownloadURL(version) {
|
||||
}
|
||||
function getStableHelmVersion() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return toolCache.downloadTool(helmLatestReleaseUrl).then((downloadPath) => {
|
||||
const response = JSON.parse(fs.readFileSync(downloadPath, 'utf8').toString().trim());
|
||||
if (!response.tag_name) {
|
||||
return stableHelmVersion;
|
||||
}
|
||||
return response.tag_name;
|
||||
}, (error) => {
|
||||
core.debug(error);
|
||||
core.warning(util.format("Failed to read latest kubectl version from stable.txt. From URL %s. Using default stable version %s", helmLatestReleaseUrl, stableHelmVersion));
|
||||
return stableHelmVersion;
|
||||
});
|
||||
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 || [];
|
||||
@ -78,7 +110,7 @@ var walkSync = function (dir, filelist, fileToFind) {
|
||||
function downloadHelm(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!version) {
|
||||
version = yield getStableHelmVersion();
|
||||
version = yield getLatestHelmVersionFor("v3");
|
||||
}
|
||||
let cachedToolpath = toolCache.find(helmToolName, version);
|
||||
if (!cachedToolpath) {
|
||||
@ -101,6 +133,45 @@ function downloadHelm(version) {
|
||||
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 = [];
|
||||
@ -115,10 +186,35 @@ function findHelm(rootFolder) {
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = yield getStableHelmVersion();
|
||||
if (process.env['HELM_INSTALLER_LEGACY_VERSIONING'] == 'true') {
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = yield getStableHelmVersion();
|
||||
}
|
||||
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));
|
||||
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);
|
||||
});
|
||||
|
6095
package-lock.json
generated
6095
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@ -6,18 +6,24 @@
|
||||
"author": "Anumita Shenoy",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/tool-cache": "1.1.2",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/io": "^1.0.0",
|
||||
"@actions/core": "^1.0.0",
|
||||
"@actions/exec": "^1.0.0"
|
||||
"@actions/tool-cache": "1.1.2",
|
||||
"@octokit/graphql": "^4.6.1",
|
||||
"semver": "^6.1.0"
|
||||
},
|
||||
"main": "lib/run.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "jest",
|
||||
"test-coverage": "jest --coverage"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.0.10",
|
||||
"typescript": "^3.5.2"
|
||||
"typescript": "^3.5.2",
|
||||
"jest": "^26.0.1",
|
||||
"@types/jest": "^25.2.2",
|
||||
"ts-jest": "^25.5.1"
|
||||
}
|
||||
}
|
||||
|
169
src/run.ts
169
src/run.ts
@ -1,26 +1,33 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as fs from 'fs';
|
||||
import * as semver from 'semver';
|
||||
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
import { graphql } from '@octokit/graphql';
|
||||
|
||||
const helmToolName = 'helm';
|
||||
const stableHelmVersion = 'v2.14.1';
|
||||
const helmLatestReleaseUrl = 'https://api.github.com/repos/helm/helm/releases/latest';
|
||||
const stableHelmVersion = 'v3.2.1';
|
||||
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';
|
||||
|
||||
function getExecutableExtension(): string {
|
||||
export function getExecutableExtension(): string {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function getHelmDownloadURL(version: string): string {
|
||||
export function getHelmDownloadURL(version: string): string {
|
||||
switch (os.type()) {
|
||||
case 'Linux':
|
||||
return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version);
|
||||
@ -31,46 +38,52 @@ function getHelmDownloadURL(version: string): string {
|
||||
case 'Windows_NT':
|
||||
default:
|
||||
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async function getStableHelmVersion(): Promise<string> {
|
||||
return toolCache.downloadTool(helmLatestReleaseUrl).then((downloadPath) => {
|
||||
const response = JSON.parse(fs.readFileSync(downloadPath, 'utf8').toString().trim());
|
||||
if (!response.tag_name)
|
||||
{
|
||||
return stableHelmVersion;
|
||||
}
|
||||
|
||||
return response.tag_name;
|
||||
}, (error) => {
|
||||
core.debug(error);
|
||||
core.warning(util.format("Failed to read latest kubectl version from stable.txt. From URL %s. Using default stable version %s", helmLatestReleaseUrl, stableHelmVersion));
|
||||
return stableHelmVersion;
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
var walkSync = function(dir, filelist, fileToFind) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
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;
|
||||
};
|
||||
|
||||
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);
|
||||
if (!cachedToolpath) {
|
||||
@ -78,7 +91,7 @@ async function downloadHelm(version: string): Promise<string> {
|
||||
try {
|
||||
helmDownloadPath = await toolCache.downloadTool(getHelmDownloadURL(version));
|
||||
} 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');
|
||||
@ -88,32 +101,100 @@ async function downloadHelm(version: string): Promise<string> {
|
||||
|
||||
const helmpath = findHelm(cachedToolpath);
|
||||
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');
|
||||
return helmpath;
|
||||
}
|
||||
|
||||
function findHelm(rootFolder: string): string {
|
||||
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 {
|
||||
fs.chmodSync(rootFolder, '777');
|
||||
var filelist: string[] = [];
|
||||
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
|
||||
if (!filelist) {
|
||||
throw new Error(util.format("Helm executable not found in path ", rootFolder));
|
||||
if (!filelist || filelist.length == 0) {
|
||||
throw new Error(util.format("Helm executable not found in path", rootFolder));
|
||||
}
|
||||
else {
|
||||
return filelist[0];
|
||||
}
|
||||
}
|
||||
|
||||
async function run() {
|
||||
export async function run() {
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = await getStableHelmVersion();
|
||||
|
||||
if (process.env['HELM_INSTALLER_LEGACY_VERSIONING'] == 'true') {
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = await getStableHelmVersion();
|
||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||
version = 'v' + version;
|
||||
}
|
||||
} else {
|
||||
if (version.toLocaleLowerCase() === 'latest' || version === LATEST_HELM3_VERSION) {
|
||||
version = await getLatestHelmVersionFor("v3");
|
||||
} else if (version === LATEST_HELM2_VERSION) {
|
||||
version = await getLatestHelmVersionFor("v2");
|
||||
} else if (!version.toLocaleLowerCase().startsWith('v')) {
|
||||
version = 'v' + version;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
//"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
@ -45,7 +45,7 @@
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
|
Reference in New Issue
Block a user