From c532a6d68b76dd5963f19d846af8d2e6de8a01fb Mon Sep 17 00:00:00 2001 From: hamza iftikhar Date: Thu, 8 Aug 2024 13:03:58 -0400 Subject: [PATCH 1/3] Add regex for stage setup or teardown jobs --- config/regex.js | 4 +++- test/config/regex.test.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/config/regex.js b/config/regex.js index 58c9485d..2d29b557 100644 --- a/config/regex.js +++ b/config/regex.js @@ -121,5 +121,7 @@ module.exports = { // Provider Role. Can be arn:aws:iam::xxxxxx:role/some-role ROLE_ARN: /^arn:aws:iam::\d{12}:role\/.+/, // Stage setup pattern. Can be stage@stage-name:setup - STAGE_SETUP_PATTERN: /^stage@([\w-]+):setup$/ + STAGE_SETUP_PATTERN: /^stage@([\w-]+):setup$/, + // Stage setup pattern. Can be stage@stage-name:setup or stage@stage-name:teardown + STAGE_SETUP_TEARDOWN_PATTERN: /^stage@([\w-]+):(setup|teardown)$/ }; diff --git a/test/config/regex.test.js b/test/config/regex.test.js index c32324e7..f5745a0c 100644 --- a/test/config/regex.test.js +++ b/test/config/regex.test.js @@ -524,4 +524,20 @@ describe('config regex', () => { }); }); }); + + describe('stageSetupTeardown', () => { + const stageSetupTeardownRegex = config.regex.STAGE_SETUP_TEARDOWN_PATTERN; + + it('matches valid stage setup or teardown jobs', () => { + ['stage@alpha:setup', 'stage@alpha:teardown'].forEach(trigger => { + assert.isTrue(stageSetupTeardownRegex.test(trigger)); + }); + }); + + it('does not match invalid stage setup or teardown jobs', () => { + ['stage@alpha', 'alpha-deploy', 'alpha:setup', 'stage@setup'].forEach(trigger => { + assert.isFalse(stageSetupTeardownRegex.test(trigger)); + }); + }); + }); }); From 9524b05731a65b26617beca240903ba6d91e0154 Mon Sep 17 00:00:00 2001 From: hamza iftikhar Date: Thu, 8 Aug 2024 14:23:12 -0400 Subject: [PATCH 2/3] Make the tests more elaborate --- config/regex.js | 6 +++--- test/config/regex.test.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config/regex.js b/config/regex.js index 2d29b557..f172133b 100644 --- a/config/regex.js +++ b/config/regex.js @@ -45,6 +45,8 @@ module.exports = { JOB_NAME: /^(([\w-]+)|(?:stage@([\w-]+):(setup|teardown)))$/, // PR JOB Name can only be PR-1 or PR-1:main, group1: PR-prNum, group2: jobName PR_JOB_NAME: /^(PR-\d+)(?::([\w-]+))?$/, + // Stage setup pattern. Can be stage@stage-name:setup or stage@stage-name:teardown + STAGE_SETUP_TEARDOWN_JOB_NAME: /^stage@([\w-]+):(setup|teardown)$/, // Match all possible job name ALL_JOB_NAME: /^(PR-[0-9]+:)?[\w-@:]+$/, // Internal trigger like ~component or ~main @@ -121,7 +123,5 @@ module.exports = { // Provider Role. Can be arn:aws:iam::xxxxxx:role/some-role ROLE_ARN: /^arn:aws:iam::\d{12}:role\/.+/, // Stage setup pattern. Can be stage@stage-name:setup - STAGE_SETUP_PATTERN: /^stage@([\w-]+):setup$/, - // Stage setup pattern. Can be stage@stage-name:setup or stage@stage-name:teardown - STAGE_SETUP_TEARDOWN_PATTERN: /^stage@([\w-]+):(setup|teardown)$/ + STAGE_SETUP_PATTERN: /^stage@([\w-]+):setup$/ }; diff --git a/test/config/regex.test.js b/test/config/regex.test.js index f5745a0c..10a56b5a 100644 --- a/test/config/regex.test.js +++ b/test/config/regex.test.js @@ -526,7 +526,7 @@ describe('config regex', () => { }); describe('stageSetupTeardown', () => { - const stageSetupTeardownRegex = config.regex.STAGE_SETUP_TEARDOWN_PATTERN; + const stageSetupTeardownRegex = config.regex.STAGE_SETUP_TEARDOWN_JOB_NAME; it('matches valid stage setup or teardown jobs', () => { ['stage@alpha:setup', 'stage@alpha:teardown'].forEach(trigger => { @@ -535,7 +535,16 @@ describe('config regex', () => { }); it('does not match invalid stage setup or teardown jobs', () => { - ['stage@alpha', 'alpha-deploy', 'alpha:setup', 'stage@setup'].forEach(trigger => { + [ + 'stage@alpha', + 'alpha-deploy', + 'alpha:setup', + 'stage@setup', + 'stage@alpha:deploy', + 'stage@teardown', + 'sd@1234:stage@alpha:setup', + 'sd@1234:stage@alpha:teardown' + ].forEach(trigger => { assert.isFalse(stageSetupTeardownRegex.test(trigger)); }); }); From c39e96451f529d208896e67c0a800d6ba0342325 Mon Sep 17 00:00:00 2001 From: hamza iftikhar Date: Thu, 8 Aug 2024 15:05:54 -0400 Subject: [PATCH 3/3] Comments update --- config/regex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/regex.js b/config/regex.js index f172133b..478a97cf 100644 --- a/config/regex.js +++ b/config/regex.js @@ -45,7 +45,7 @@ module.exports = { JOB_NAME: /^(([\w-]+)|(?:stage@([\w-]+):(setup|teardown)))$/, // PR JOB Name can only be PR-1 or PR-1:main, group1: PR-prNum, group2: jobName PR_JOB_NAME: /^(PR-\d+)(?::([\w-]+))?$/, - // Stage setup pattern. Can be stage@stage-name:setup or stage@stage-name:teardown + // Stage setup or teardown job name. Can be stage@stage-name:setup or stage@stage-name:teardown STAGE_SETUP_TEARDOWN_JOB_NAME: /^stage@([\w-]+):(setup|teardown)$/, // Match all possible job name ALL_JOB_NAME: /^(PR-[0-9]+:)?[\w-@:]+$/,