mirror of
https://github.com/Azure/k8s-deploy.git
synced 2026-04-08 22:32:16 +08:00
Supporting both comma and new line as delimiters for manifests (#133)
* Supporting both comma and new line as delimiters for manifests * Removing whitespace from manifests * Comments * PR comments * Adding ; as delimiter * Added lib files * Changed to CRLF
This commit is contained in:
parent
88c4504f60
commit
bba73cd11a
@ -166,6 +166,111 @@ test("run() - deploy - Manifiest not provided", async () => {
|
|||||||
expect(coreMock.setFailed).toBeCalledWith('No manifests supplied to deploy');
|
expect(coreMock.setFailed).toBeCalledWith('No manifests supplied to deploy');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("run() - deploy - Only one manifest with no delimiters", async () => {
|
||||||
|
const kubectlVersion = 'v1.18.0'
|
||||||
|
coreMock.getInput = jest.fn().mockImplementation((name) => {
|
||||||
|
if (name == 'manifests') {
|
||||||
|
return "bg-smi.yml";
|
||||||
|
}
|
||||||
|
if (name == 'action') {
|
||||||
|
return 'deploy';
|
||||||
|
}
|
||||||
|
return kubectlVersion;
|
||||||
|
});
|
||||||
|
coreMock.setFailed = jest.fn();
|
||||||
|
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
|
||||||
|
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
|
||||||
|
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
|
||||||
|
fileUtility.chmodSync = jest.fn();
|
||||||
|
|
||||||
|
//Invoke and assert
|
||||||
|
await expect(action.run()).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("run() - deploy - Manifests provided by new line delimiter", async () => {
|
||||||
|
const kubectlVersion = 'v1.18.0'
|
||||||
|
coreMock.getInput = jest.fn().mockImplementation((name) => {
|
||||||
|
if (name == 'manifests') {
|
||||||
|
return "bg-smi.yml\n bg.yml\ndeployment.yml";
|
||||||
|
}
|
||||||
|
if (name == 'action') {
|
||||||
|
return 'deploy';
|
||||||
|
}
|
||||||
|
return kubectlVersion;
|
||||||
|
});
|
||||||
|
coreMock.setFailed = jest.fn();
|
||||||
|
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
|
||||||
|
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
|
||||||
|
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
|
||||||
|
fileUtility.chmodSync = jest.fn();
|
||||||
|
|
||||||
|
//Invoke and assert
|
||||||
|
await expect(action.run()).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("run() - deploy - Manifests provided by comma as a delimiter", async () => {
|
||||||
|
const kubectlVersion = 'v1.18.0'
|
||||||
|
coreMock.getInput = jest.fn().mockImplementation((name) => {
|
||||||
|
if (name == 'manifests') {
|
||||||
|
return "bg-smi.yml, bg.yml, deployment.yml";
|
||||||
|
}
|
||||||
|
if (name == 'action') {
|
||||||
|
return 'deploy';
|
||||||
|
}
|
||||||
|
return kubectlVersion;
|
||||||
|
});
|
||||||
|
coreMock.setFailed = jest.fn();
|
||||||
|
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
|
||||||
|
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
|
||||||
|
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
|
||||||
|
fileUtility.chmodSync = jest.fn();
|
||||||
|
|
||||||
|
//Invoke and assert
|
||||||
|
await expect(action.run()).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("run() - deploy - Manifests provided by both new line and comma as a delimiter", async () => {
|
||||||
|
const kubectlVersion = 'v1.18.0'
|
||||||
|
coreMock.getInput = jest.fn().mockImplementation((name) => {
|
||||||
|
if (name == 'manifests') {
|
||||||
|
return "bg-smi.yml\nbg.yml,deployment.yml";
|
||||||
|
}
|
||||||
|
if (name == 'action') {
|
||||||
|
return 'deploy';
|
||||||
|
}
|
||||||
|
return kubectlVersion;
|
||||||
|
});
|
||||||
|
coreMock.setFailed = jest.fn();
|
||||||
|
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
|
||||||
|
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
|
||||||
|
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
|
||||||
|
fileUtility.chmodSync = jest.fn();
|
||||||
|
|
||||||
|
//Invoke and assert
|
||||||
|
await expect(action.run()).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("run() - deploy - Manifests provided by both new line and comma and semi-colon as a delimiter", async () => {
|
||||||
|
const kubectlVersion = 'v1.18.0'
|
||||||
|
coreMock.getInput = jest.fn().mockImplementation((name) => {
|
||||||
|
if (name == 'manifests') {
|
||||||
|
return "bg-smi.yml\nbg.yml,deployment.yml;bg.yml";
|
||||||
|
}
|
||||||
|
if (name == 'action') {
|
||||||
|
return 'deploy';
|
||||||
|
}
|
||||||
|
return kubectlVersion;
|
||||||
|
});
|
||||||
|
coreMock.setFailed = jest.fn();
|
||||||
|
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
|
||||||
|
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
|
||||||
|
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
|
||||||
|
fileUtility.chmodSync = jest.fn();
|
||||||
|
|
||||||
|
//Invoke and assert
|
||||||
|
await expect(action.run()).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
test("deployment - deploy() - Invokes with no manifestfiles", async () => {
|
test("deployment - deploy() - Invokes with no manifestfiles", async () => {
|
||||||
const kubeCtl: jest.Mocked<Kubectl> = new Kubectl("") as any;
|
const kubeCtl: jest.Mocked<Kubectl> = new Kubectl("") as any;
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ const core = require("@actions/core");
|
|||||||
exports.namespace = core.getInput('namespace');
|
exports.namespace = core.getInput('namespace');
|
||||||
exports.containers = core.getInput('images').split('\n');
|
exports.containers = core.getInput('images').split('\n');
|
||||||
exports.imagePullSecrets = core.getInput('imagepullsecrets').split('\n').filter(secret => secret.trim().length > 0);
|
exports.imagePullSecrets = core.getInput('imagepullsecrets').split('\n').filter(secret => secret.trim().length > 0);
|
||||||
exports.manifests = core.getInput('manifests').split('\n');
|
exports.manifests = core.getInput('manifests').split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0);
|
||||||
exports.canaryPercentage = core.getInput('percentage');
|
exports.canaryPercentage = core.getInput('percentage');
|
||||||
exports.deploymentStrategy = core.getInput('strategy');
|
exports.deploymentStrategy = core.getInput('strategy');
|
||||||
exports.trafficSplitMethod = core.getInput('traffic-split-method');
|
exports.trafficSplitMethod = core.getInput('traffic-split-method');
|
||||||
|
|||||||
@ -70,7 +70,12 @@ function run() {
|
|||||||
namespace = 'default';
|
namespace = 'default';
|
||||||
}
|
}
|
||||||
let action = core.getInput('action');
|
let action = core.getInput('action');
|
||||||
let manifests = manifestsInput.split('\n');
|
let manifests = manifestsInput.split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0);
|
||||||
|
if (manifests.length > 0) {
|
||||||
|
manifests = manifests.map(manifest => {
|
||||||
|
return manifest.trim();
|
||||||
|
});
|
||||||
|
}
|
||||||
if (action === 'deploy') {
|
if (action === 'deploy') {
|
||||||
let strategy = core.getInput('strategy');
|
let strategy = core.getInput('strategy');
|
||||||
console.log("strategy: ", strategy);
|
console.log("strategy: ", strategy);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import * as core from '@actions/core';
|
|||||||
export let namespace: string = core.getInput('namespace');
|
export let namespace: string = core.getInput('namespace');
|
||||||
export const containers: string[] = core.getInput('images').split('\n');
|
export const containers: string[] = core.getInput('images').split('\n');
|
||||||
export const imagePullSecrets: string[] = core.getInput('imagepullsecrets').split('\n').filter(secret => secret.trim().length > 0);
|
export const imagePullSecrets: string[] = core.getInput('imagepullsecrets').split('\n').filter(secret => secret.trim().length > 0);
|
||||||
export const manifests = core.getInput('manifests').split('\n');
|
export const manifests = core.getInput('manifests').split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0);
|
||||||
export const canaryPercentage: string = core.getInput('percentage');
|
export const canaryPercentage: string = core.getInput('percentage');
|
||||||
export const deploymentStrategy: string = core.getInput('strategy');
|
export const deploymentStrategy: string = core.getInput('strategy');
|
||||||
export const trafficSplitMethod: string = core.getInput('traffic-split-method');
|
export const trafficSplitMethod: string = core.getInput('traffic-split-method');
|
||||||
|
|||||||
@ -59,7 +59,13 @@ export async function run() {
|
|||||||
namespace = 'default';
|
namespace = 'default';
|
||||||
}
|
}
|
||||||
let action = core.getInput('action');
|
let action = core.getInput('action');
|
||||||
let manifests = manifestsInput.split('\n');
|
let manifests = manifestsInput.split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0);
|
||||||
|
|
||||||
|
if (manifests.length > 0) {
|
||||||
|
manifests = manifests.map(manifest => {
|
||||||
|
return manifest.trim();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (action === 'deploy') {
|
if (action === 'deploy') {
|
||||||
let strategy = core.getInput('strategy');
|
let strategy = core.getInput('strategy');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user