Skip to content

Commit

Permalink
feat(3020): change to support pipeline template (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
klu909 authored Feb 27, 2024
1 parent 630d437 commit 3fb6822
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
25 changes: 17 additions & 8 deletions config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,24 @@ const SCHEMA_SUBSCRIBE = Joi.object().keys({

const SCHEMA_CONFIG = Joi.object()
.keys({
template: Joi.string().regex(Regex.FULL_TEMPLATE_NAME_WITH_NAMESPACE),
version: Joi.number().integer().min(1).max(50),
annotations: Annotations.annotations,
jobs: SCHEMA_JOBS.required(),
shared: SCHEMA_SHARED,
cache: SCHEMA_CACHE,
childPipelines: SCHEMA_CHILD_PIPELINES,
stages: SCHEMA_STAGES,
subscribe: SCHEMA_SUBSCRIBE,
parameters: Parameters.parameters.default({})
annotations: Annotations.annotations.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
jobs: SCHEMA_JOBS.when('template', { is: Joi.exist(), then: Joi.forbidden(), otherwise: Joi.required() }),
shared: Joi.when('template', {
is: Joi.exist(),
then: Joi.object().keys({
image: Job.image,
environment: Job.environment,
settings: Job.settings
}),
otherwise: SCHEMA_SHARED
}),
cache: SCHEMA_CACHE.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
childPipelines: SCHEMA_CHILD_PIPELINES.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
stages: SCHEMA_STAGES.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
subscribe: SCHEMA_SUBSCRIBE.when('template', { is: Joi.exist(), then: Joi.forbidden() }),
parameters: Parameters.parameters.default({}).when('template', { is: Joi.exist(), then: Joi.forbidden() })
})
.unknown(false);

Expand Down
14 changes: 14 additions & 0 deletions test/config/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@ describe('config base', () => {
assert.isNull(validate('config.base.stages.yaml', config.base.stages).error);
});
});

describe('pipeline template', () => {
it('validates the basic pipeline template usage', () => {
assert.isNull(validate('config.base.pipelineTemplate.yaml', config.base.config).error);
});

it('if template is provided then unsupported fields are foridden', () => {
assert.isNotNull(validate('config.base.pipelineTemplate-forbidden.yaml', config.base.config).error);
});

it('if template is not provided then job is required', () => {
assert.isNotNull(validate('config.base.pipelineTemplate-invalid.yaml', config.base.config).error);
});
});
});
13 changes: 13 additions & 0 deletions test/data/config.base.pipelineTemplate-forbidden.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
template: foo/[email protected]
shared:
image: node:20
environment:
FOO: user overwrite
settings:
email: [email protected]
jobs:
main:
required: [ ~commit ]
steps:
- init: npm install
- test: npm test
1 change: 1 addition & 0 deletions test/data/config.base.pipelineTemplate-invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 1
7 changes: 7 additions & 0 deletions test/data/config.base.pipelineTemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
template: foo/[email protected]
shared:
image: node:20
environment:
FOO: user overwrite
settings:
email: [email protected]

0 comments on commit 3fb6822

Please sign in to comment.