Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(3161): Add support to allow remote triggers for a stage #572

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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-]+))?$/,
// External Stage trigger like ~sd@26:stage@alpha:setup
EXTERNAL_STAGE_TRIGGER: /^~?sd@\d+:(?:([\w-]+)|(stage@([\w-]+):(setup|teardown)))$/,
// 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'
].forEach(trigger => {
assert.isTrue(stageExternalTriggerRegex.test(trigger));
});
});

it('does not match invalid stage external triggers', () => {
[
'sd@26:stage@alpha:deploy',
'~sd@26:stage@alpha:deploy',
'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