Skip to content

Commit bba73cd

Browse files
authored
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
1 parent 88c4504 commit bba73cd

File tree

5 files changed

+120
-4
lines changed

5 files changed

+120
-4
lines changed

__tests__/run.test.ts

+105
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,111 @@ test("run() - deploy - Manifiest not provided", async () => {
166166
expect(coreMock.setFailed).toBeCalledWith('No manifests supplied to deploy');
167167
});
168168

169+
test("run() - deploy - Only one manifest with no delimiters", async () => {
170+
const kubectlVersion = 'v1.18.0'
171+
coreMock.getInput = jest.fn().mockImplementation((name) => {
172+
if (name == 'manifests') {
173+
return "bg-smi.yml";
174+
}
175+
if (name == 'action') {
176+
return 'deploy';
177+
}
178+
return kubectlVersion;
179+
});
180+
coreMock.setFailed = jest.fn();
181+
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
182+
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
183+
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
184+
fileUtility.chmodSync = jest.fn();
185+
186+
//Invoke and assert
187+
await expect(action.run()).resolves.not.toThrow();
188+
});
189+
190+
test("run() - deploy - Manifests provided by new line delimiter", async () => {
191+
const kubectlVersion = 'v1.18.0'
192+
coreMock.getInput = jest.fn().mockImplementation((name) => {
193+
if (name == 'manifests') {
194+
return "bg-smi.yml\n bg.yml\ndeployment.yml";
195+
}
196+
if (name == 'action') {
197+
return 'deploy';
198+
}
199+
return kubectlVersion;
200+
});
201+
coreMock.setFailed = jest.fn();
202+
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
203+
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
204+
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
205+
fileUtility.chmodSync = jest.fn();
206+
207+
//Invoke and assert
208+
await expect(action.run()).resolves.not.toThrow();
209+
});
210+
211+
test("run() - deploy - Manifests provided by comma as a delimiter", async () => {
212+
const kubectlVersion = 'v1.18.0'
213+
coreMock.getInput = jest.fn().mockImplementation((name) => {
214+
if (name == 'manifests') {
215+
return "bg-smi.yml, bg.yml, deployment.yml";
216+
}
217+
if (name == 'action') {
218+
return 'deploy';
219+
}
220+
return kubectlVersion;
221+
});
222+
coreMock.setFailed = jest.fn();
223+
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
224+
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
225+
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
226+
fileUtility.chmodSync = jest.fn();
227+
228+
//Invoke and assert
229+
await expect(action.run()).resolves.not.toThrow();
230+
});
231+
232+
test("run() - deploy - Manifests provided by both new line and comma as a delimiter", async () => {
233+
const kubectlVersion = 'v1.18.0'
234+
coreMock.getInput = jest.fn().mockImplementation((name) => {
235+
if (name == 'manifests') {
236+
return "bg-smi.yml\nbg.yml,deployment.yml";
237+
}
238+
if (name == 'action') {
239+
return 'deploy';
240+
}
241+
return kubectlVersion;
242+
});
243+
coreMock.setFailed = jest.fn();
244+
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
245+
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
246+
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
247+
fileUtility.chmodSync = jest.fn();
248+
249+
//Invoke and assert
250+
await expect(action.run()).resolves.not.toThrow();
251+
});
252+
253+
test("run() - deploy - Manifests provided by both new line and comma and semi-colon as a delimiter", async () => {
254+
const kubectlVersion = 'v1.18.0'
255+
coreMock.getInput = jest.fn().mockImplementation((name) => {
256+
if (name == 'manifests') {
257+
return "bg-smi.yml\nbg.yml,deployment.yml;bg.yml";
258+
}
259+
if (name == 'action') {
260+
return 'deploy';
261+
}
262+
return kubectlVersion;
263+
});
264+
coreMock.setFailed = jest.fn();
265+
toolCacheMock.find = jest.fn().mockReturnValue(undefined);
266+
toolCacheMock.downloadTool = jest.fn().mockReturnValue('downloadpath');
267+
toolCacheMock.cacheFile = jest.fn().mockReturnValue('cachepath');
268+
fileUtility.chmodSync = jest.fn();
269+
270+
//Invoke and assert
271+
await expect(action.run()).resolves.not.toThrow();
272+
});
273+
169274
test("deployment - deploy() - Invokes with no manifestfiles", async () => {
170275
const kubeCtl: jest.Mocked<Kubectl> = new Kubectl("") as any;
171276

lib/input-parameters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const core = require("@actions/core");
55
exports.namespace = core.getInput('namespace');
66
exports.containers = core.getInput('images').split('\n');
77
exports.imagePullSecrets = core.getInput('imagepullsecrets').split('\n').filter(secret => secret.trim().length > 0);
8-
exports.manifests = core.getInput('manifests').split('\n');
8+
exports.manifests = core.getInput('manifests').split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0);
99
exports.canaryPercentage = core.getInput('percentage');
1010
exports.deploymentStrategy = core.getInput('strategy');
1111
exports.trafficSplitMethod = core.getInput('traffic-split-method');

lib/run.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ function run() {
7070
namespace = 'default';
7171
}
7272
let action = core.getInput('action');
73-
let manifests = manifestsInput.split('\n');
73+
let manifests = manifestsInput.split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0);
74+
if (manifests.length > 0) {
75+
manifests = manifests.map(manifest => {
76+
return manifest.trim();
77+
});
78+
}
7479
if (action === 'deploy') {
7580
let strategy = core.getInput('strategy');
7681
console.log("strategy: ", strategy);

src/input-parameters.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as core from '@actions/core';
55
export let namespace: string = core.getInput('namespace');
66
export const containers: string[] = core.getInput('images').split('\n');
77
export const imagePullSecrets: string[] = core.getInput('imagepullsecrets').split('\n').filter(secret => secret.trim().length > 0);
8-
export const manifests = core.getInput('manifests').split('\n');
8+
export const manifests = core.getInput('manifests').split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0);
99
export const canaryPercentage: string = core.getInput('percentage');
1010
export const deploymentStrategy: string = core.getInput('strategy');
1111
export const trafficSplitMethod: string = core.getInput('traffic-split-method');

src/run.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ export async function run() {
5959
namespace = 'default';
6060
}
6161
let action = core.getInput('action');
62-
let manifests = manifestsInput.split('\n');
62+
let manifests = manifestsInput.split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0);
63+
64+
if (manifests.length > 0) {
65+
manifests = manifests.map(manifest => {
66+
return manifest.trim();
67+
});
68+
}
6369

6470
if (action === 'deploy') {
6571
let strategy = core.getInput('strategy');

0 commit comments

Comments
 (0)