From 8d257fed50cbfb53ec882259808a95ac31c0162c Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 14 Apr 2021 14:14:06 +0530 Subject: [PATCH 1/5] Supporting both comma and new line as delimiters for manifests --- __tests__/run.test.ts | 63 +++++++++++++++++++++++++++++++++++++++++ src/input-parameters.ts | 2 +- src/run.ts | 2 +- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/__tests__/run.test.ts b/__tests__/run.test.ts index e161966f..bd5b59e1 100644 --- a/__tests__/run.test.ts +++ b/__tests__/run.test.ts @@ -210,6 +210,69 @@ test("run() - deploy - Manifiest not provided", async () => { expect(coreMock.setFailed).toBeCalledWith('No manifests supplied to deploy'); }); +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\nbg.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("deployment - deploy() - Invokes with no manifestfiles", async () => { const kubeCtl: jest.Mocked = new Kubectl("") as any; diff --git a/src/input-parameters.ts b/src/input-parameters.ts index feb03454..3f9a09ef 100644 --- a/src/input-parameters.ts +++ b/src/input-parameters.ts @@ -5,7 +5,7 @@ import * as core from '@actions/core'; export let namespace: string = core.getInput('namespace'); 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 manifests = core.getInput('manifests').split('\n'); +export const manifests = core.getInput('manifests').split(/[\n,]+/); export const canaryPercentage: string = core.getInput('percentage'); export const deploymentStrategy: string = core.getInput('strategy'); export const trafficSplitMethod: string = core.getInput('traffic-split-method'); diff --git a/src/run.ts b/src/run.ts index b96e516b..073dd27c 100644 --- a/src/run.ts +++ b/src/run.ts @@ -59,7 +59,7 @@ export async function run() { namespace = 'default'; } let action = core.getInput('action'); - let manifests = manifestsInput.split('\n'); + let manifests = manifestsInput.split(/[\n,]+/); if (action === 'deploy') { let strategy = core.getInput('strategy'); From 625898f6eb0b0c2a3c6cb79f1bb6342ea84fd848 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 14 Apr 2021 14:31:04 +0530 Subject: [PATCH 2/5] Removing whitespace from manifests --- src/run.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/run.ts b/src/run.ts index 073dd27c..c16dcc21 100644 --- a/src/run.ts +++ b/src/run.ts @@ -61,6 +61,12 @@ export async function run() { let action = core.getInput('action'); let manifests = manifestsInput.split(/[\n,]+/); + if (manifests.length > 0) { + manifests = manifests.map(manifest => { + return manifest.trim(); + }); + } + if (action === 'deploy') { let strategy = core.getInput('strategy'); console.log("strategy: ", strategy) From ee4b5d33e0805f0305feaed9afefdb5be8f1a988 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 14 Apr 2021 15:31:19 +0530 Subject: [PATCH 3/5] Comments --- __tests__/run.test.ts | 25 +++++++++++++++++++++++-- src/input-parameters.ts | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/__tests__/run.test.ts b/__tests__/run.test.ts index bd5b59e1..1dd795f0 100644 --- a/__tests__/run.test.ts +++ b/__tests__/run.test.ts @@ -210,11 +210,32 @@ test("run() - deploy - Manifiest not provided", async () => { 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\nbg.yml\ndeployment.yml"; + return "bg-smi.yml\n bg.yml\ndeployment.yml"; } if (name == 'action') { return 'deploy'; @@ -235,7 +256,7 @@ 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"; + return "bg-smi.yml, bg.yml, deployment.yml"; } if (name == 'action') { return 'deploy'; diff --git a/src/input-parameters.ts b/src/input-parameters.ts index 3f9a09ef..166541db 100644 --- a/src/input-parameters.ts +++ b/src/input-parameters.ts @@ -5,7 +5,7 @@ import * as core from '@actions/core'; export let namespace: string = core.getInput('namespace'); 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 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 deploymentStrategy: string = core.getInput('strategy'); export const trafficSplitMethod: string = core.getInput('traffic-split-method'); From a58ad23e7ff39e944715f0c4af7b48f68e1370ac Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Wed, 14 Apr 2021 20:05:45 +0530 Subject: [PATCH 4/5] PR comments --- src/run.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run.ts b/src/run.ts index c16dcc21..42942a0f 100644 --- a/src/run.ts +++ b/src/run.ts @@ -59,7 +59,7 @@ export async function run() { namespace = 'default'; } 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 => { From 2577009bcb64af46af40fa34764e581a60538457 Mon Sep 17 00:00:00 2001 From: Ganeshrockz Date: Thu, 15 Apr 2021 11:35:18 +0530 Subject: [PATCH 5/5] Adding ; as delimiter --- __tests__/run.test.ts | 21 +++++++++++++++++++++ src/input-parameters.ts | 2 +- src/run.ts | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/__tests__/run.test.ts b/__tests__/run.test.ts index 1dd795f0..74261649 100644 --- a/__tests__/run.test.ts +++ b/__tests__/run.test.ts @@ -294,6 +294,27 @@ test("run() - deploy - Manifests provided by both new line and comma as a delimi 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 () => { const kubeCtl: jest.Mocked = new Kubectl("") as any; diff --git a/src/input-parameters.ts b/src/input-parameters.ts index 166541db..58259bbe 100644 --- a/src/input-parameters.ts +++ b/src/input-parameters.ts @@ -5,7 +5,7 @@ import * as core from '@actions/core'; export let namespace: string = core.getInput('namespace'); 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 manifests = core.getInput('manifests').split(/[\n,]+/).filter(manifest => manifest.trim().length > 0); +export const manifests = core.getInput('manifests').split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0); export const canaryPercentage: string = core.getInput('percentage'); export const deploymentStrategy: string = core.getInput('strategy'); export const trafficSplitMethod: string = core.getInput('traffic-split-method'); diff --git a/src/run.ts b/src/run.ts index 42942a0f..d68660e3 100644 --- a/src/run.ts +++ b/src/run.ts @@ -59,7 +59,7 @@ export async function run() { namespace = 'default'; } let action = core.getInput('action'); - let manifests = manifestsInput.split(/[\n,]+/).filter(manifest => manifest.trim().length > 0); + let manifests = manifestsInput.split(/[\n,;]+/).filter(manifest => manifest.trim().length > 0); if (manifests.length > 0) { manifests = manifests.map(manifest => {