mirror of
https://github.com/Azure/setup-helm.git
synced 2025-07-16 19:00:35 +00:00
Compare commits
23 Commits
v1.1
...
adding-cod
Author | SHA1 | Date | |
---|---|---|---|
a1ff1b2bed | |||
feeafa6152 | |||
b8c59ed1e4 | |||
14d85694fc | |||
cfc72cf63e | |||
470bf91618 | |||
0a4da9a67f | |||
07143cd16a | |||
dcb450d677 | |||
1571d72e78 | |||
62aeada586 | |||
edc063ca5f | |||
e77e49c8f8 | |||
d315e938e1 | |||
509333604f | |||
91b7d21636 | |||
b1c4524a5f | |||
f404b8932e | |||
1de6b70ec6 | |||
d0d63812ab | |||
87a2cd59a0 | |||
fe2c706cad | |||
11c996f4c7 |
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@ -0,0 +1 @@
|
||||
* @ds-ms
|
10
.github/ISSUE_TEMPLATE/issue--bug-report---feature-request.md
vendored
Normal file
10
.github/ISSUE_TEMPLATE/issue--bug-report---feature-request.md
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
---
|
||||
name: 'Issue: Bug Report / Feature Request'
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: need-to-triage
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
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
|
36
.github/workflows/defaultLabels.yml
vendored
Normal file
36
.github/workflows/defaultLabels.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
name: setting-default-labels
|
||||
|
||||
# Controls when the action will run.
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0/3 * * *"
|
||||
|
||||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||
jobs:
|
||||
build:
|
||||
# The type of runner that the job will run on
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
|
||||
- uses: actions/stale@v3
|
||||
name: Setting issue as idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: 'This issue is idle because it has been open for 14 days with no activity.'
|
||||
stale-issue-label: 'idle'
|
||||
days-before-stale: 14
|
||||
days-before-close: -1
|
||||
operations-per-run: 100
|
||||
exempt-issue-labels: 'backlog'
|
||||
|
||||
- uses: actions/stale@v3
|
||||
name: Setting PR as idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-pr-message: 'This PR is idle because it has been open for 14 days with no activity.'
|
||||
stale-pr-label: 'idle'
|
||||
days-before-stale: 14
|
||||
days-before-close: -1
|
||||
operations-per-run: 100
|
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');
|
||||
});
|
||||
});
|
@ -5,6 +5,10 @@ inputs:
|
||||
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);
|
||||
});
|
||||
|
124
package-lock.json
generated
124
package-lock.json
generated
@ -5,9 +5,9 @@
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@actions/core": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.0.0.tgz",
|
||||
"integrity": "sha512-aMIlkx96XH4E/2YZtEOeyrYQfhlas9jIRkfGPqMwXD095Rdkzo4lB6ZmbxPQSzD+e1M+Xsm98ZhuSMYGv/AlqA=="
|
||||
"version": "1.2.6",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
||||
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA=="
|
||||
},
|
||||
"@actions/exec": {
|
||||
"version": "1.0.0",
|
||||
@ -24,12 +24,12 @@
|
||||
"resolved": "https://registry.npmjs.org/@actions/tool-cache/-/tool-cache-1.1.2.tgz",
|
||||
"integrity": "sha512-IJczPaZr02ECa3Lgws/TJEVco9tjOujiQSZbO3dHuXXjhd5vrUtfOgGwhmz3/f97L910OraPZ8SknofUk6RvOQ==",
|
||||
"requires": {
|
||||
"@actions/core": "1.1.3",
|
||||
"@actions/exec": "1.0.1",
|
||||
"@actions/io": "1.0.1",
|
||||
"semver": "6.3.0",
|
||||
"typed-rest-client": "1.5.0",
|
||||
"uuid": "3.3.3"
|
||||
"@actions/core": "^1.1.0",
|
||||
"@actions/exec": "^1.0.1",
|
||||
"@actions/io": "^1.0.1",
|
||||
"semver": "^6.1.0",
|
||||
"typed-rest-client": "^1.4.0",
|
||||
"uuid": "^3.3.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": {
|
||||
@ -49,12 +49,102 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"@octokit/endpoint": {
|
||||
"version": "6.0.11",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-6.0.11.tgz",
|
||||
"integrity": "sha512-fUIPpx+pZyoLW4GCs3yMnlj2LfoXTWDUVPTC4V3MUEKZm48W+XYpeWSZCv+vYF1ZABUm2CqnDVf1sFtIYrj7KQ==",
|
||||
"requires": {
|
||||
"@octokit/types": "^6.0.3",
|
||||
"is-plain-object": "^5.0.0",
|
||||
"universal-user-agent": "^6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-plain-object": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz",
|
||||
"integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@octokit/graphql": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.6.1.tgz",
|
||||
"integrity": "sha512-2lYlvf4YTDgZCTXTW4+OX+9WTLFtEUc6hGm4qM1nlZjzxj+arizM4aHWzBVBCxY9glh7GIs0WEuiSgbVzv8cmA==",
|
||||
"requires": {
|
||||
"@octokit/request": "^5.3.0",
|
||||
"@octokit/types": "^6.0.3",
|
||||
"universal-user-agent": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"@octokit/openapi-types": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-6.0.0.tgz",
|
||||
"integrity": "sha512-CnDdK7ivHkBtJYzWzZm7gEkanA7gKH6a09Eguz7flHw//GacPJLmkHA3f3N++MJmlxD1Fl+mB7B32EEpSCwztQ=="
|
||||
},
|
||||
"@octokit/request": {
|
||||
"version": "5.4.14",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.4.14.tgz",
|
||||
"integrity": "sha512-VkmtacOIQp9daSnBmDI92xNIeLuSRDOIuplp/CJomkvzt7M18NXgG044Cx/LFKLgjKt9T2tZR6AtJayba9GTSA==",
|
||||
"requires": {
|
||||
"@octokit/endpoint": "^6.0.1",
|
||||
"@octokit/request-error": "^2.0.0",
|
||||
"@octokit/types": "^6.7.1",
|
||||
"deprecation": "^2.0.0",
|
||||
"is-plain-object": "^5.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"once": "^1.4.0",
|
||||
"universal-user-agent": "^6.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-plain-object": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz",
|
||||
"integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@octokit/request-error": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.0.5.tgz",
|
||||
"integrity": "sha512-T/2wcCFyM7SkXzNoyVNWjyVlUwBvW3igM3Btr/eKYiPmucXTtkxt2RBsf6gn3LTzaLSLTQtNmvg+dGsOxQrjZg==",
|
||||
"requires": {
|
||||
"@octokit/types": "^6.0.3",
|
||||
"deprecation": "^2.0.0",
|
||||
"once": "^1.4.0"
|
||||
}
|
||||
},
|
||||
"@octokit/types": {
|
||||
"version": "6.13.0",
|
||||
"resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.13.0.tgz",
|
||||
"integrity": "sha512-W2J9qlVIU11jMwKHUp5/rbVUeErqelCsO5vW5PKNb7wAXQVUz87Rc+imjlEvpvbH8yUb+KHmv8NEjVZdsdpyxA==",
|
||||
"requires": {
|
||||
"@octokit/openapi-types": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.7.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.4.tgz",
|
||||
"integrity": "sha512-W0+n1Y+gK/8G2P/piTkBBN38Qc5Q1ZSO6B5H3QmPCUewaiXOo2GCAWZ4ElZCcNhjJuBSUSLGFUJnmlCn5+nxOQ==",
|
||||
"dev": true
|
||||
},
|
||||
"deprecation": {
|
||||
"version": "2.3.1",
|
||||
"resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz",
|
||||
"integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
|
||||
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"semver": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||
@ -75,9 +165,9 @@
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.6.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.2.tgz",
|
||||
"integrity": "sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==",
|
||||
"version": "3.9.9",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.9.tgz",
|
||||
"integrity": "sha512-kdMjTiekY+z/ubJCATUPlRDl39vXYiMV9iyeMuEuXZh2we6zz80uovNN2WlAxmmdE/Z/YQe+EbOEXB5RHEED3w==",
|
||||
"dev": true
|
||||
},
|
||||
"underscore": {
|
||||
@ -85,10 +175,20 @@
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
|
||||
"integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI="
|
||||
},
|
||||
"universal-user-agent": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.0.tgz",
|
||||
"integrity": "sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w=="
|
||||
},
|
||||
"uuid": {
|
||||
"version": "3.3.3",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.3.tgz",
|
||||
"integrity": "sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ=="
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
}
|
||||
}
|
||||
}
|
18
package.json
18
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"
|
||||
"build": "tsc --outDir ./lib --rootDir ./src",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
163
src/run.ts
163
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;
|
||||
}
|
||||
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 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;
|
||||
});
|
||||
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. */
|
||||
|
||||
@ -58,6 +58,7 @@
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
||||
|
Reference in New Issue
Block a user