Skip to content

Commit

Permalink
feat(3143): Add regex for stage setup or teardown job names (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThehamzaIftikhar authored Aug 8, 2024
1 parent 072b54c commit 682ad4e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 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-@:]+$/,
// Internal trigger like ~component or ~main
Expand Down
25 changes: 25 additions & 0 deletions test/config/regex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,29 @@ describe('config regex', () => {
});
});
});

describe('stageSetupTeardown', () => {
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 => {
assert.isTrue(stageSetupTeardownRegex.test(trigger));
});
});

it('does not match invalid stage setup or teardown jobs', () => {
[
'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));
});
});
});
});

0 comments on commit 682ad4e

Please sign in to comment.