Skip to content

Commit

Permalink
feat(3161): Add support to allow remote triggers for a stage
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar1312 committed Aug 2, 2024
1 parent 6688840 commit ff0dbeb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
4 changes: 3 additions & 1 deletion config/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ const SCHEMA_TRIGGER = sdJoi.string().branchFilter();
const SCHEMA_INTERNAL_TRIGGER = Joi.string().regex(Regex.INTERNAL_TRIGGER); // ~main, ~jobOne
const SCHEMA_EXTERNAL_TRIGGER = Joi.string().regex(Regex.EXTERNAL_TRIGGER_ALL).example('~sd@1234:component'); // ~sd@123:main or sd@123:main
const SCHEMA_STAGE_TRIGGER = Joi.string().regex(Regex.STAGE_TRIGGER); // ~stage@deploy, ~stage@deploy:main
const SCHEMA_EXTERNAL_STAGE_TRIGGER = Joi.string().regex(Regex.EXTERNAL_STAGE_TRIGGER); // ~sd@26:stage@alpha:setup, sd@26:stage@alpha:deploy
const SCHEMA_CRON_EXPRESSION = sdCron.string().cron();
const SCHEMA_REQUIRES_VALUE = Joi.alternatives().try(
SCHEMA_INTERNAL_TRIGGER,
SCHEMA_JOBNAME,
SCHEMA_TRIGGER,
SCHEMA_STAGE_TRIGGER
SCHEMA_STAGE_TRIGGER,
SCHEMA_EXTERNAL_STAGE_TRIGGER
);
const SCHEMA_REQUIRES = Joi.alternatives().try(Joi.array().items(SCHEMA_REQUIRES_VALUE), SCHEMA_REQUIRES_VALUE);
const SCHEMA_BLOCKEDBY_VALUE = Joi.alternatives().try(
Expand Down
3 changes: 3 additions & 0 deletions config/migrationsConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
module.exports = {
development: {
url: process.env.DEV_DATASTORE_SEQUELIZE_URL,
// dialect: 'postgres',
dialect: 'sqlite',
// dialect: 'mysql',
logging: true
},
test: {
Expand Down
12 changes: 7 additions & 5 deletions config/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ module.exports = {
QUALIFIED_STAGE_NAME: /^stage@([\w-]+)$/,
// Stage trigger like ~stage@deploy or ~stage@stageName:jobName or stage@deploy or stage@stageName:jobName
STAGE_TRIGGER: /^~?stage@([\w-]+)(?::([\w-]+))?$/,
// Stage trigger like ~sd@26:stage@alpha:setup, sd@26:stage@alpha:deploy
EXTERNAL_STAGE_TRIGGER: /^~?sd@\d+:(([\w-]+)|(stage@([\w-]+):([\w-]+)))$/,
// Don't combine EXTERNAL_TRIGGER and EXTERNAL_TRIGGER_AND for backward compatibility
// BlockBy does not support EXTERNAL_TRIGGER_AND
// External trigger like ~sd@123:component (OR case)
EXTERNAL_TRIGGER: /^~sd@(\d+):([\w-]+)$/,
// External trigger like sd@123:component (AND case)
EXTERNAL_TRIGGER_AND: /^sd@(\d+):([\w-]+)$/,
// External trigger like ~sd@123:component, ~sd@26:stage@alpha:setup (OR case)
EXTERNAL_TRIGGER: /^~sd@(\d+):(([\w-]+)|(stage@([\w-]+):setup))$/,
// External trigger like sd@123:component, sd@26:stage@alpha:setup (AND case)
EXTERNAL_TRIGGER_AND: /^sd@(\d+):(([\w-]+)|(stage@([\w-]+):setup))$/,
// External trigger (OR and AND case)
// Can be ~sd@123:component or sd@123:component
EXTERNAL_TRIGGER_ALL: /^~?sd@(\d+):([\w-]+)$/,
EXTERNAL_TRIGGER_ALL: /^~?sd@(\d+):(([\w-]+)|(stage@([\w-]+):setup))$/,

// Can be ~pr, ~commit, ~release, ~tag or ~commit:branchName, or ~sd@123:component
// Note: if you modify this regex, you must modify `sdJoi` definition in the `config/job.js`
Expand Down
30 changes: 30 additions & 0 deletions test/config/regex.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,34 @@ describe('config regex', () => {
assert.isFalse(stageTriggerRegex.test('build'));
});
});

describe('stageExternalTrigger', () => {
const stageExternalTriggerRegex = config.regex.EXTERNAL_STAGE_TRIGGER;

it('matches valid stage external triggers', () => {
[
'sd@26:stage@alpha:setup',
'~sd@26:stage@alpha:setup',
'sd@26:stage@alpha:teardown',
'~sd@26:stage@alpha:teardown',
'sd@26:stage@alpha:deploy',
'~sd@26:stage@alpha:deploy'
].forEach(trigger => {
assert.isTrue(stageExternalTriggerRegex.test(trigger));
});
});

it('does not match invalid stage external triggers', () => {
[
'sd@26:stage@alpha',
'sd@26:stage@',
'sd@26:stage:',
'stage@alpha:setup',
'stage:build:test',
'build'
].forEach(trigger => {
assert.isFalse(stageExternalTriggerRegex.test(trigger));
});
});
});
});
5 changes: 5 additions & 0 deletions test/data/config.workflowGraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ nodes:
- name: sd@123:publish
- name: sd@333:E
- name: G
- name: triggers-external-stage
- name: sd@26:stage@alpha-in-remote-pipeline:setup
edges:
- src: ~commit
dest: main
Expand All @@ -29,3 +31,6 @@ edges:
- src: sd@333:E
dest: G
join: true
- src: triggers-external-stage
dest: sd@26:stage@alpha-in-remote-pipeline:setup
join: true

0 comments on commit ff0dbeb

Please sign in to comment.