Updated workflows, codeowner, .gitignore, tsconfig (#49)

* Updated workflows, codeowner, .gitignore, tsconfig

* Fixing test discrepancies

* Fixing paths

* Fixing paths

* fixing int tests

* Fixing int test

* Fixing int test
This commit is contained in:
Tommy Barnes 2022-02-04 13:33:14 -05:00 коммит произвёл GitHub
Родитель ab9b258333
Коммит f97e9efd05
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
15 изменённых файлов: 29 добавлений и 764 удалений

2
.github/CODEOWNERS поставляемый
Просмотреть файл

@ -1 +1 @@
* @OliverMKing @rsamigullin
* @Azure/aks-atlanta

3
.github/workflows/integration-tests.yaml поставляемый
Просмотреть файл

@ -20,7 +20,8 @@ jobs:
- name: Building latest changes
run: |
cd k8s-bake
npm install --prod
npm i
npm run build
- name: Bake using Helm on ${{ matrix.os }}
uses: ./k8s-bake

52
.github/workflows/release-pr.yml поставляемый
Просмотреть файл

@ -1,4 +1,4 @@
name: "Create release PR"
name: Create release PR
on:
workflow_dispatch:
@ -8,49 +8,7 @@ on:
required: true
jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check if remote branch exists
env:
BRANCH: releases/${{ github.event.inputs.release }}
run: |
echo "##[set-output name=exists;]$(echo $(if [[ -z $(git ls-remote --heads origin ${BRANCH}) ]]; then echo false; else echo true; fi;))"
id: extract-branch-status
# these two only need to occur if the branch exists
- name: Checkout proper branch
if: ${{ steps.extract-branch-status.outputs.exists == 'true' }}
env:
BRANCH: releases/${{ github.event.inputs.release }}
run: git checkout ${BRANCH}
- name: Reset promotion branch
if: ${{ steps.extract-branch-status.outputs.exists == 'true' }}
run: |
git fetch origin main:main
git reset --hard main
- name: Install packages
run: |
rm -rf node_modules/
npm install --no-bin-links
npm run build
- name: Remove node_modules from gitignore
run: |
sed -i '/node_modules/d' ./.gitignore
- name: Create branch
uses: peterjgrainger/action-create-branch@v2.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: releases/${{ github.event.inputs.release }}
- name: Create pull request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Add node modules and new code for release
title: ${{ github.event.inputs.release }} new release
base: releases/${{ github.event.inputs.release }}
branch: create-release
delete-branch: true
release-pr:
uses: OliverMKing/javascript-release-workflow/.github/workflows/release-pr.yml@main
with:
release: ${{ github.event.inputs.release }}

10
.github/workflows/tag-and-draft.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,10 @@
name: Tag and create release draft
on:
push:
branches:
- releases/*
jobs:
tag-and-release:
uses: OliverMKing/javascript-release-workflow/.github/workflows/tag-and-release.yml@main

77
.github/workflows/tag-and-release.yml поставляемый
Просмотреть файл

@ -1,77 +0,0 @@
name: "Tag and create release draft"
on:
push:
branches:
- releases/*
jobs:
gh_tagged_release:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Test release
run: |
sudo npm install n
sudo n latest
npm test
- name: Get branch ending
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/} | sed 's:.*/::')"
id: extract-branch
- name: Get tags
run: |
echo "##[set-output name=tags;]$(echo $(git tag))"
id: extract-tags
- name: Get latest tag
uses: actions/github-script@v5
env:
TAGS: ${{ steps.extract-tags.outputs.tags }}
BRANCH: ${{ steps.extract-branch.outputs.branch }}
with:
script: |
const tags = process.env["TAGS"]
.split(" ")
.map((x) => x.trim());
const branch = process.env["BRANCH"];
const splitTag = (x) =>
x
.substring(branch.length + 1)
.split(".")
.map((x) => Number(x));
function compareTags(nums1, nums2, position = 0) {
if (nums1.length < position && nums2.length < position) return nums2;
const num1 = splitTag(nums1)[position] || 0;
const num2 = splitTag(nums2)[position] || 0;
if (num1 === num2) return compareTags(nums1, nums2, position + 1);
else if (num1 > num2) return nums1;
else return nums2;
}
const branchTags = tags.filter((tag) => tag.startsWith(branch));
if (branchTags.length < 1) return branch + ".-1"
return branchTags.reduce((prev, curr) => compareTags(prev, curr));
result-encoding: string
id: get-latest-tag
- name: Get new tag
uses: actions/github-script@v5
env:
PREV: ${{ steps.get-latest-tag.outputs.result }}
with:
script: |
let version = process.env["PREV"]
if (!version.includes(".")) version += ".0"; // case of v1 or v2
const prefix = /^([a-zA-Z]+)/.exec(version)[0];
const numbers = version.substring(prefix.length);
let split = numbers.split(".");
split[split.length - 1] = parseInt(split[split.length - 1]) + 1;
return prefix + split.join(".");
result-encoding: string
id: get-new-tag
- uses: "marvinpinto/action-automatic-releases@v1.2.1"
with:
title: ${{ steps.get-new-tag.outputs.result }} release
automatic_release_tag: ${{ steps.get-new-tag.outputs.result }}
repo_token: "${{ secrets.GITHUB_TOKEN }}"
draft: true

Просмотреть файл

@ -1,107 +0,0 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
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) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.installHelm = exports.getHelmPath = exports.findHelm = exports.downloadHelm = exports.walkSync = void 0;
const path = require("path");
const fs = require("fs");
const util = require("util");
const toolCache = require("@actions/tool-cache");
const core = require("@actions/core");
const io = require("@actions/io");
const utilities_1 = require("./utilities");
const helmToolName = 'helm';
function walkSync(dir, filelist = [], fileToFind) {
const files = fs.readdirSync(dir);
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;
}
exports.walkSync = walkSync;
;
function downloadHelm(version) {
return __awaiter(this, void 0, void 0, function* () {
if (!version) {
version = yield (0, utilities_1.getStableVerison)(helmToolName);
}
let cachedToolpath = toolCache.find(helmToolName, version);
if (!cachedToolpath) {
cachedToolpath = yield (0, utilities_1.setCachedToolPath)(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');
const filelist = [];
walkSync(rootFolder, filelist, helmToolName + (0, utilities_1.getExecutableExtension)());
if (!filelist) {
throw new Error(util.format("Helm executable not found in path ", rootFolder));
}
else {
return filelist[0];
}
}
exports.findHelm = findHelm;
function getHelmPath() {
return __awaiter(this, void 0, void 0, function* () {
let helmPath = "";
const version = core.getInput('helm-version', { required: false });
if (version) {
if (!!version && version != utilities_1.LATEST) {
helmPath = toolCache.find(helmToolName, version);
}
if (!helmPath) {
helmPath = yield installHelm(version);
}
}
else {
helmPath = yield io.which(helmToolName, false);
if (!helmPath) {
const allVersions = toolCache.findAllVersions(helmToolName);
helmPath = allVersions.length > 0 ? toolCache.find(helmToolName, allVersions[0]) : '';
if (!helmPath) {
throw new Error('helm is not installed, either add setup-helm action or provide "helm-version" input to download helm');
}
helmPath = path.join(helmPath, `helm${(0, utilities_1.getExecutableExtension)()}`);
}
}
core.debug(util.format("Helm executable path %s", helmPath));
return helmPath;
});
}
exports.getHelmPath = getHelmPath;
function installHelm(version) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, utilities_1.isEqual)(version, utilities_1.LATEST)) {
version = yield (0, utilities_1.getStableVerison)(helmToolName);
}
core.debug(util.format("Downloading helm version %s", version));
return yield downloadHelm(version);
});
}
exports.installHelm = installHelm;

Просмотреть файл

@ -1,72 +0,0 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
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) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.installKompose = exports.downloadKompose = exports.getKomposePath = void 0;
const path = require("path");
const fs = require("fs");
const util = require("util");
const toolCache = require("@actions/tool-cache");
const core = require("@actions/core");
const io = require("@actions/io");
const utilities_1 = require("./utilities");
const komposeToolName = 'kompose';
const stableKomposeVersion = "v1.18.0";
function getKomposePath() {
return __awaiter(this, void 0, void 0, function* () {
let komposePath = "";
const version = core.getInput('kompose-version', { required: false });
if (version) {
if (!!version && version != utilities_1.LATEST) {
komposePath = toolCache.find(komposeToolName, version);
}
if (!komposePath) {
komposePath = yield installKompose(version);
}
}
else {
komposePath = yield io.which(komposeToolName, false);
if (!komposePath) {
const allVersions = toolCache.findAllVersions(komposeToolName);
komposePath = allVersions.length > 0 ? toolCache.find(komposeToolName, allVersions[0]) : '';
if (!komposePath) {
throw new Error('kompose is not installed, provide "kompose-version" input to download kompose');
}
komposePath = path.join(komposePath, `kompose${(0, utilities_1.getExecutableExtension)()}`);
}
}
return komposePath;
});
}
exports.getKomposePath = getKomposePath;
function downloadKompose(version = stableKomposeVersion) {
return __awaiter(this, void 0, void 0, function* () {
let cachedToolpath = toolCache.find(komposeToolName, version);
if (!cachedToolpath) {
cachedToolpath = yield (0, utilities_1.setCachedToolPath)(komposeToolName, version);
}
const komposePath = path.join(cachedToolpath, komposeToolName + (0, utilities_1.getExecutableExtension)());
fs.chmodSync(komposePath, 0o100); // execute/search by owner permissions to the tool
return komposePath;
});
}
exports.downloadKompose = downloadKompose;
function installKompose(version) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, utilities_1.isEqual)(version, utilities_1.LATEST)) {
version = stableKomposeVersion;
}
core.debug(util.format("Downloading kompose version %s", version));
return yield downloadKompose(version);
});
}
exports.installKompose = installKompose;

Просмотреть файл

@ -1,75 +0,0 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
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) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.installKubectl = exports.getKubectlPath = exports.downloadKubectl = void 0;
const path = require("path");
const fs = require("fs");
const util = require("util");
const toolCache = require("@actions/tool-cache");
const core = require("@actions/core");
const io = require("@actions/io");
const utilities_1 = require("./utilities");
const kubectlToolName = 'kubectl';
function downloadKubectl(version) {
return __awaiter(this, void 0, void 0, function* () {
if (!version) {
version = yield (0, utilities_1.getStableVerison)(kubectlToolName);
}
let cachedToolpath = toolCache.find(kubectlToolName, version);
if (!cachedToolpath) {
cachedToolpath = yield (0, utilities_1.setCachedToolPath)(kubectlToolName, version);
}
const kubectlPath = path.join(cachedToolpath, kubectlToolName + (0, utilities_1.getExecutableExtension)());
fs.chmodSync(kubectlPath, '777');
return kubectlPath;
});
}
exports.downloadKubectl = downloadKubectl;
function getKubectlPath() {
return __awaiter(this, void 0, void 0, function* () {
let kubectlPath = "";
const version = core.getInput('kubectl-version', { required: false });
if (version) {
if (!!version && version != utilities_1.LATEST) {
const cachedToolPath = toolCache.find(kubectlToolName, version);
kubectlPath = path.join(cachedToolPath, kubectlToolName + (0, utilities_1.getExecutableExtension)());
}
if (!kubectlPath) {
kubectlPath = yield installKubectl(version);
}
}
else {
kubectlPath = yield io.which(kubectlToolName, false);
if (!kubectlPath) {
const allVersions = toolCache.findAllVersions(kubectlToolName);
kubectlPath = allVersions.length > 0 ? toolCache.find(kubectlToolName, allVersions[0]) : '';
if (!kubectlPath) {
throw new Error('Kubectl is not installed, either add install-kubectl action or provide "kubectl-version" input to download kubectl');
}
kubectlPath = path.join(kubectlPath, `kubectl${(0, utilities_1.getExecutableExtension)()}`);
}
}
return kubectlPath;
});
}
exports.getKubectlPath = getKubectlPath;
function installKubectl(version) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, utilities_1.isEqual)(version, utilities_1.LATEST)) {
version = yield (0, utilities_1.getStableVerison)(kubectlToolName);
}
core.debug(util.format("Downloading kubectl version %s", version));
return yield downloadKubectl(version);
});
}
exports.installKubectl = installKubectl;

Просмотреть файл

@ -1,221 +0,0 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
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) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.KustomizeRenderEngine = exports.KomposeRenderEngine = exports.HelmRenderEngine = void 0;
const core = require("@actions/core");
const ioUtil = require("@actions/io/lib/io-util");
const utilities = require("./utilities");
const path = require("path");
const fs = require("fs");
const util = require("util");
const helm_util_1 = require("./helm-util");
const kubectl_util_1 = require("./kubectl-util");
const kompose_util_1 = require("./kompose-util");
class RenderEngine {
constructor() {
this.getTemplatePath = () => {
const tempDirectory = process.env['RUNNER_TEMP'];
if (!!tempDirectory) {
return path.join(tempDirectory, 'baked-template-' + utilities.getCurrentTime().toString() + '.yaml');
}
else {
throw Error("Unable to create temp directory.");
}
};
}
}
class HelmRenderEngine extends RenderEngine {
constructor() {
super(...arguments);
this.bake = (isSilent) => __awaiter(this, void 0, void 0, function* () {
const helmPath = yield (0, helm_util_1.getHelmPath)();
const chartPath = core.getInput('helmChart', { required: true });
const options = {
silent: isSilent
};
const dependencyArgs = this.getDependencyArgs(chartPath);
console.log("Running helm dependency update command..");
yield utilities.execCommand(helmPath, dependencyArgs, options);
console.log("Getting helm version..");
let isV3 = true;
yield this.isHelmV3(helmPath).then((result) => { isV3 = result; }).catch(() => { isV3 = false; });
try {
if (!isV3) {
yield utilities.execCommand(helmPath, ['init', '--client-only', '--stable-repo-url', 'https://charts.helm.sh/stable'], options);
}
}
catch (ex) {
core.warning(util.format('Could not run helm init command: ', ex));
}
console.log("Creating the template argument string..");
const args = this.getTemplateArgs(chartPath, isV3);
console.log("Running helm template command..");
const result = yield utilities.execCommand(helmPath, args, options);
const pathToBakedManifest = this.getTemplatePath();
fs.writeFileSync(pathToBakedManifest, result.stdout);
core.setOutput('manifestsBundle', pathToBakedManifest);
});
}
getOverrideValues(overrides) {
const overrideValues = [];
overrides.forEach(arg => {
const overrideInput = arg.split(':');
const overrideName = overrideInput[0];
const overrideValue = overrideInput.slice(1).join(':');
overrideValues.push({
name: overrideName,
value: overrideValue
});
});
return overrideValues;
}
getDependencyArgs(chartPath) {
let args = [];
args.push('dependency');
args.push('update');
args.push(chartPath);
return args;
}
getTemplateArgs(chartPath, isV3) {
const releaseName = core.getInput('releaseName', { required: false });
let args = [];
args.push('template');
if (isV3) {
if (releaseName) {
args.push(releaseName);
}
}
else {
if (releaseName) {
args.push('--name');
args.push(releaseName);
}
}
args.push(chartPath);
const overrideFilesInput = core.getInput('overrideFiles', { required: false });
if (!!overrideFilesInput) {
core.debug("Adding overrides file inputs");
const overrideFiles = overrideFilesInput.split('\n');
if (overrideFiles.length > 0) {
overrideFiles.forEach(file => {
args.push('-f');
args.push(file);
});
}
}
const overridesInput = core.getInput('overrides', { required: false });
if (!!overridesInput) {
core.debug("Adding overrides inputs");
const overrides = overridesInput.split('\n');
if (overrides.length > 0) {
const overrideValues = this.getOverrideValues(overrides);
overrideValues.forEach(overrideValue => {
args.push('--set');
args.push(`${overrideValue.name}=${overrideValue.value}`);
});
}
}
return args;
}
isHelmV3(path) {
return __awaiter(this, void 0, void 0, function* () {
let result = yield utilities.execCommand(path, ["version", "--template", "{{.Version}}"], { silent: true });
return result.stdout.split('.')[0] === 'v3';
});
}
}
exports.HelmRenderEngine = HelmRenderEngine;
class KomposeRenderEngine extends RenderEngine {
constructor() {
super(...arguments);
this.bake = (isSilent) => __awaiter(this, void 0, void 0, function* () {
const dockerComposeFilePath = core.getInput('dockerComposeFile', { required: true });
if (!ioUtil.exists(dockerComposeFilePath)) {
throw Error(util.format("Docker compose file path %s does not exist. Please check the path specified", dockerComposeFilePath));
}
const options = {
silent: isSilent
};
const komposePath = yield (0, kompose_util_1.getKomposePath)();
const pathToBakedManifest = this.getTemplatePath();
core.debug("Running kompose command..");
yield utilities.execCommand(komposePath, ['convert', '-f', dockerComposeFilePath, '-o', pathToBakedManifest], options);
core.setOutput('manifestsBundle', pathToBakedManifest);
});
}
}
exports.KomposeRenderEngine = KomposeRenderEngine;
class KustomizeRenderEngine extends RenderEngine {
constructor() {
super(...arguments);
this.bake = (isSilent) => __awaiter(this, void 0, void 0, function* () {
const kubectlPath = yield (0, kubectl_util_1.getKubectlPath)();
yield this.validateKustomize(kubectlPath);
const kustomizationPath = core.getInput('kustomizationPath', { required: true });
if (!ioUtil.exists(kustomizationPath)) {
throw Error(util.format("kustomizationPath %s does not exist. Please check whether file exists or not.", kustomizationPath));
}
const options = {
silent: isSilent
};
core.debug("Running kubectl kustomize command..");
console.log(`[command] ${kubectlPath} kustomize ${core.getInput('kustomizationPath')}`);
const result = yield utilities.execCommand(kubectlPath, ['kustomize', kustomizationPath], options);
const pathToBakedManifest = this.getTemplatePath();
fs.writeFileSync(pathToBakedManifest, result.stdout);
core.setOutput('manifestsBundle', pathToBakedManifest);
});
}
validateKustomize(kubectlPath) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield utilities.execCommand(kubectlPath, ['version', '--client=true', '-o', 'json']);
if (!!result.stdout) {
const clientVersion = JSON.parse(result.stdout).clientVersion;
const versionNumber = `${clientVersion.major}.${clientVersion.minor}`;
if (!clientVersion || parseFloat(versionNumber) < parseFloat(utilities.MIN_KUBECTL_CLIENT_VERSION)) {
throw new Error("kubectl client version equal to v1.14 or higher is required to use kustomize features");
}
}
});
}
}
exports.KustomizeRenderEngine = KustomizeRenderEngine;
function run() {
return __awaiter(this, void 0, void 0, function* () {
const renderType = core.getInput('renderEngine', { required: true });
let renderEngine;
switch (renderType) {
case 'helm':
case 'helm2':
renderEngine = new HelmRenderEngine();
break;
case 'kompose':
renderEngine = new KomposeRenderEngine();
break;
case 'kustomize':
renderEngine = new KustomizeRenderEngine();
break;
default:
throw Error("Unknown render engine");
}
let isSilent = core.getInput('silent', { required: false }) === 'false';
try {
yield renderEngine.bake(isSilent);
}
catch (err) {
throw Error(util.format("Failed to run bake action. Error: %s", err));
}
});
}
exports.run = run;
run().catch(core.setFailed);

Просмотреть файл

@ -1,152 +0,0 @@
"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
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) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MIN_KUBECTL_CLIENT_VERSION = exports.LATEST = exports.getStableVerison = exports.getDownloadUrl = exports.setCachedToolPath = exports.execCommand = exports.getExecutableExtension = exports.isEqual = exports.getCurrentTime = void 0;
const os = require("os");
const fs = require("fs");
const util = require("util");
const toolrunner_1 = require("@actions/exec/lib/toolrunner");
const toolCache = require("@actions/tool-cache");
const core = require("@actions/core");
function getCurrentTime() {
return new Date().getTime();
}
exports.getCurrentTime = getCurrentTime;
function isEqual(str1, str2) {
if (!str1)
str1 = "";
if (!str2)
str2 = "";
return str1.toLowerCase() === str2.toLowerCase();
}
exports.isEqual = isEqual;
function getExecutableExtension() {
if (os.type().match(/^Win/)) {
return '.exe';
}
return '';
}
exports.getExecutableExtension = getExecutableExtension;
function execCommand(toolPath, args, options = {}) {
return __awaiter(this, void 0, void 0, function* () {
const execResult = {
stdout: "",
stderr: ""
};
options.listeners = {
stdout: (data) => {
execResult.stdout += data.toString();
},
stderr: (data) => {
execResult.stderr += data.toString();
}
};
let toolRunner = new toolrunner_1.ToolRunner(toolPath, args, options);
const result = yield toolRunner.exec();
if (result != 0) {
if (!!execResult.stderr) {
throw Error(execResult.stderr);
}
else {
throw Error(util.format("%s exited with result code %s", toolPath, result));
}
}
return execResult;
});
}
exports.execCommand = execCommand;
function setCachedToolPath(toolName, version) {
return __awaiter(this, void 0, void 0, function* () {
let cachedToolpath = '';
let downloadPath = '';
const downloadUrl = getDownloadUrl(toolName, version);
try {
downloadPath = yield toolCache.downloadTool(downloadUrl);
}
catch (exeption) {
throw new Error(`Failed to download the ${toolName} from ${downloadUrl}. Error: ${exeption}`);
}
if (toolName == 'helm') {
fs.chmodSync(downloadPath, '777');
const unzipedHelmPath = yield toolCache.extractZip(downloadPath);
cachedToolpath = yield toolCache.cacheDir(unzipedHelmPath, toolName, version);
}
else {
cachedToolpath = yield toolCache.cacheFile(downloadPath, toolName + getExecutableExtension(), toolName, version);
}
return cachedToolpath;
});
}
exports.setCachedToolPath = setCachedToolPath;
function getDownloadUrl(toolName, version) {
const system = os.type();
const systemAndArch = system == "Linux" ? `${system}_${os.arch()}` : system;
if (!downloadLinks[systemAndArch] || !downloadLinks[systemAndArch][toolName]) {
throw Error("Unknown OS or render engine type");
}
return util.format(downloadLinks[systemAndArch][toolName], version);
}
exports.getDownloadUrl = getDownloadUrl;
function getStableVerison(toolName) {
return __awaiter(this, void 0, void 0, function* () {
if (!stableVersionUrls[toolName]) {
throw Error("Unable to download. Unknown tool name");
}
return toolCache.downloadTool(stableVersionUrls[toolName]).then(downloadPath => {
let response = fs.readFileSync(downloadPath, 'utf8').toString().trim();
if (toolName == 'helm') {
const versionTag = JSON.parse(response);
return versionTag.tag_name ? versionTag.tag_name : defaultStableHelmVersion;
}
else {
return response ? response : defaultStableKubectlVersion;
}
}, err => {
core.debug(err);
core.warning(util.format("Failed to read latest %s version from URL %s. Using default stable version %s", toolName, stableVersionUrls[toolName], toolName == 'helm' ? defaultStableHelmVersion : defaultStableKubectlVersion));
return toolName == 'helm' ? defaultStableHelmVersion : defaultStableKubectlVersion;
});
});
}
exports.getStableVerison = getStableVerison;
const defaultStableHelmVersion = 'v2.14.1';
const defaultStableKubectlVersion = 'v1.15.0';
const stableVersionUrls = {
'kubectl': 'https://storage.googleapis.com/kubernetes-release/release/stable.txt',
'helm': 'https://api.github.com/repos/helm/helm/releases/latest',
};
const downloadLinks = {
'Linux_x64': {
'helm' : 'https://get.helm.sh/helm-%s-linux-amd64.zip',
'kompose' : 'https://github.com/kubernetes/kompose/releases/download/%s/kompose-linux-amd64',
'kubectl' : 'https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/amd64/kubectl'
},
'Linux_arm64': {
'helm' : 'https://get.helm.sh/helm-%s-linux-arm64.zip',
'kompose' : 'https://github.com/kubernetes/kompose/releases/download/%s/kompose-linux-arm64',
'kubectl' : 'https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/arm64/kubectl'
},
'Darwin': {
'helm': 'https://get.helm.sh/helm-%s-darwin-amd64.zip',
'kompose': 'https://github.com/kubernetes/kompose/releases/download/%s/kompose-darwin-amd64',
'kubectl': 'https://storage.googleapis.com/kubernetes-release/release/%s/bin/darwin/amd64/kubectl'
},
'Windows_NT': {
'helm': 'https://get.helm.sh/helm-%s-windows-amd64.zip',
'kompose': 'https://github.com/kubernetes/kompose/releases/download/%s/kompose-windows-amd64.exe',
'kubectl': 'https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/amd64/kubectl.exe'
}
};
exports.LATEST = 'latest';
exports.MIN_KUBECTL_CLIENT_VERSION = "1.14";

Просмотреть файл

@ -1,11 +1,11 @@
import * as helmUtil from '../src/helm-util';
import * as helmUtil from './helm-util';
import * as os from 'os';
import * as fs from 'fs';
import * as path from 'path';
import * as toolCache from '@actions/tool-cache';
import * as core from '@actions/core';
import * as io from '@actions/io';
import * as utils from '../src/utilities';
import * as utils from './utilities';
describe('Testing all funcitons in helm-util file.', () => {

Просмотреть файл

@ -1,4 +1,4 @@
import * as komposeUtil from '../src/kompose-util';
import * as komposeUtil from './kompose-util';
import * as os from 'os';
import * as fs from 'fs';
import * as path from 'path';

Просмотреть файл

@ -1,11 +1,11 @@
import * as kubectlUtil from '../src/kubectl-util';
import * as kubectlUtil from './kubectl-util';
import * as os from 'os';
import * as fs from 'fs';
import * as path from 'path';
import * as toolCache from '@actions/tool-cache';
import * as core from '@actions/core';
import * as io from '@actions/io';
import * as utils from '../src/utilities';
import * as utils from './utilities';
describe('Testing all funcitons in kubectl-util file.', () => {

Просмотреть файл

@ -1,8 +1,8 @@
import * as helmUtil from '../src/helm-util';
import * as kubectlUtil from '../src/kubectl-util';
import * as komposeUtil from '../src/kompose-util';
import * as utils from '../src/utilities';
import { KustomizeRenderEngine, KomposeRenderEngine, HelmRenderEngine, run } from '../src/run';
import * as helmUtil from './helm-util';
import * as kubectlUtil from './kubectl-util';
import * as komposeUtil from './kompose-util';
import * as utils from './utilities';
import { KustomizeRenderEngine, KomposeRenderEngine, HelmRenderEngine, run } from './run';
import * as ioUtil from '@actions/io/lib/io-util';
import * as os from 'os';
import * as fs from 'fs';

Просмотреть файл

@ -3,7 +3,7 @@ import * as fs from 'fs';
import * as toolCache from '@actions/tool-cache';
import { ExecOptions } from "@actions/exec/lib/interfaces";
import * as core from '@actions/core';
import * as utils from '../src/utilities';
import * as utils from './utilities';
var mockStatusCode, stdOutMessage, stdErrMessage;
const mockExecFn = jest.fn().mockImplementation((toolPath, args, options) => {