Skip to content

Commit

Permalink
feat: add column templateVersionId to pipeline (#554)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: renamed base.config to base.configAfterMergingTemplate
  • Loading branch information
klu909 authored Mar 1, 2024
1 parent 3fb6822 commit 0811f06
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
20 changes: 18 additions & 2 deletions config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const SCHEMA_SUBSCRIBE = Joi.object().keys({
)
});

const SCHEMA_CONFIG = Joi.object()
const SCHEMA_CONFIG_PRE_TEMPLATE_MERGE = Joi.object()
.keys({
template: Joi.string().regex(Regex.FULL_TEMPLATE_NAME_WITH_NAMESPACE),
version: Joi.number().integer().min(1).max(50),
Expand All @@ -86,6 +86,21 @@ const SCHEMA_CONFIG = Joi.object()
})
.unknown(false);

const SCHEMA_CONFIG_POST_TEMPLATE_MERGE = Joi.object()
.keys({
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({}),
templateVersionId: Joi.number().integer().positive().optional().allow(null)
})
.unknown(false);

/**
* Main pieces of a screwdriver.yaml
* @type {Object}
Expand All @@ -97,7 +112,8 @@ module.exports = {
cache: SCHEMA_CACHE,
cachePerm: SCHEMA_CACHE_PERMUTATION,
childPipelines: SCHEMA_CHILD_PIPELINES,
config: SCHEMA_CONFIG,
configBeforeMergingTemplate: SCHEMA_CONFIG_PRE_TEMPLATE_MERGE,
configAfterMergingTemplate: SCHEMA_CONFIG_POST_TEMPLATE_MERGE,
stageSetupTeardownJob: SCHEMA_SETUP_TEARDOWN_JOB,
stage: SCHEMA_STAGE,
stages: SCHEMA_STAGES,
Expand Down
27 changes: 27 additions & 0 deletions migrations/20240228-add_column_templateVersionId_to_pipeline.JS
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable new-cap */

'use strict';

const prefix = process.env.DATASTORE_SEQUELIZE_PREFIX || '';
const table = `${prefix}pipelines`;

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.sequelize.transaction(async transaction => {
await queryInterface.addColumn(
table,
'templateVersionId',
{
type: Sequelize.INTEGER.UNSIGNED
},
{ transaction }
);

await queryInterface.addIndex(table, {
name: `${table}_template_version_id`,
fields: ['templateVersionId'],
transaction
});
});
}
};
11 changes: 10 additions & 1 deletion models/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,15 @@ const MODEL = {
})
.description('A list of badges that pipline has')
.example(`{ sonar: { name: 'dashboard', uri: 'http://sonar.com/sample1' } }`)
.optional(),

templateVersionId: Joi.number()
.integer()
.positive()
.description("Identifier for this pipeline's template")
.example(123345)
.optional()
.allow(null)
};

const UPDATE_MODEL = { ...CREATE_MODEL, settings: MODEL.settings, badges: MODEL.badges };
Expand Down Expand Up @@ -156,7 +164,8 @@ module.exports = {
'parameters',
'subscribedScmUrlsWithActions',
'settings',
'badges'
'badges',
'templateVersionId'
]
)
).label('Get Pipeline'),
Expand Down
12 changes: 8 additions & 4 deletions test/config/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { validate } = require('../helper');
describe('config base', () => {
describe('config', () => {
it('validates a screwdriver config', () => {
assert.isNull(validate('config.base.config.yaml', config.base.config).error);
assert.isNull(validate('config.base.config.yaml', config.base.configAfterMergingTemplate).error);
});
});

Expand Down Expand Up @@ -47,15 +47,19 @@ describe('config base', () => {

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

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

it('if template is not provided then job is required', () => {
assert.isNotNull(validate('config.base.pipelineTemplate-invalid.yaml', config.base.config).error);
assert.isNotNull(
validate('config.base.pipelineTemplate-invalid.yaml', config.base.configBeforeMergingTemplate).error
);
});
});
});
2 changes: 2 additions & 0 deletions test/data/config.base.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ stages:
image: node:{{NODE_VERSION}}
steps:
- publish: publish blog post

templateVersionId: 111
3 changes: 2 additions & 1 deletion test/data/config.base.pipelineTemplate-invalid.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
version: 1
version: 1
templateVersionId: 111
1 change: 1 addition & 0 deletions test/data/pipeline.get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ subscribedScmUrlsWithActions:
- scmUri: github.com:34568912:master
actions: [commit, tag, release]
state: ACTIVE
templateVersionId: 1234567

0 comments on commit 0811f06

Please sign in to comment.