From 045816da6acefb46da451a777fcb7324cc371d93 Mon Sep 17 00:00:00 2001 From: klu909 <55161078+klu909@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:07:53 -0700 Subject: [PATCH] feat(3059): Add pipeline level customization for pipeline template (#560) --- config/base.js | 10 ++-- config/pipelineTemplate.js | 13 ++-- test/data/config.base.pipelineTemplate.yaml | 30 ++++++++-- test/data/config.pipelineTemplate.yaml | 66 ++++++++++++++++++++- 4 files changed, 102 insertions(+), 17 deletions(-) diff --git a/config/base.js b/config/base.js index fc07f33a..71ea960a 100644 --- a/config/base.js +++ b/config/base.js @@ -67,7 +67,7 @@ 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), - annotations: Annotations.annotations.when('template', { is: Joi.exist(), then: Joi.forbidden() }), + annotations: Annotations.annotations, jobs: SCHEMA_JOBS.when('template', { is: Joi.exist(), then: Joi.forbidden(), otherwise: Joi.required() }), shared: Joi.when('template', { is: Joi.exist(), @@ -78,11 +78,11 @@ const SCHEMA_CONFIG_PRE_TEMPLATE_MERGE = Joi.object() }), 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() }), + cache: SCHEMA_CACHE, + childPipelines: SCHEMA_CHILD_PIPELINES, 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() }) + subscribe: SCHEMA_SUBSCRIBE, + parameters: Parameters.parameters.default({}) }) .unknown(false); diff --git a/config/pipelineTemplate.js b/config/pipelineTemplate.js index 7741d9ed..260b367a 100644 --- a/config/pipelineTemplate.js +++ b/config/pipelineTemplate.js @@ -1,17 +1,20 @@ 'use strict'; const Joi = require('joi'); -const JobsSchema = require('./base').jobs; -const Shared = require('./base').shared; +const BaseSchema = require('./base'); +const Annotations = require('./annotations'); const Parameters = require('./parameters'); const Template = require('./template'); const Regex = require('./regex'); const SCHEMA_CONFIG = Joi.object() .keys({ - jobs: JobsSchema.required(), - shared: Shared, - parameters: Parameters.parameters.default({}) + jobs: BaseSchema.jobs.required(), + shared: BaseSchema.shared, + parameters: Parameters.parameters.default({}), + annotations: Annotations.annotations, + cache: BaseSchema.cache, + subscribe: BaseSchema.subscribe }) .unknown(false); diff --git a/test/data/config.base.pipelineTemplate.yaml b/test/data/config.base.pipelineTemplate.yaml index d51cb84f..679dc60a 100644 --- a/test/data/config.base.pipelineTemplate.yaml +++ b/test/data/config.base.pipelineTemplate.yaml @@ -1,7 +1,27 @@ template: foo/bar@1.0.0 shared: - image: node:20 - environment: - FOO: user overwrite - settings: - email: foo@example.com \ No newline at end of file + image: node:20 + environment: + FOO: user overwrite + settings: + email: foo@example.com +cache: + pipeline: ["node_modules/", "~/.sbt"] + event: ["target/generated-intermediate-resouce/*"] + job: + build: ["target/some-artifact.zip"] + publish-preview: ["target/some-artifact.zip"] + test: [] +subscribe: + scmUrls: + - git@github.com:foo/bar.git#master: [~commit, ~tags, ~release] +annotations: + foo: a + bar: b +parameters: + color: [red, blue] +childPipelines: + scmUrls: + - git@github.com:org/repo.git + - https://github.com:org/repo2.git + startAll: true \ No newline at end of file diff --git a/test/data/config.pipelineTemplate.yaml b/test/data/config.pipelineTemplate.yaml index 2e0636f5..76dee8ad 100644 --- a/test/data/config.pipelineTemplate.yaml +++ b/test/data/config.pipelineTemplate.yaml @@ -6,7 +6,69 @@ maintainer: foo@bar.com config: jobs: main: + requires: + - ~commit + - ~pr + - ~subscribe steps: - - init: npm install - - test: npm test + - hello: echo hello + shared: + image: node:20 + environment: + FOO: user overwrite + settings: + email: foo@example.com + blockedBy: [~main] + cache: true + description: 'This is a description!' + annotations: + foo: a + bar: b + freezeWindows: + - "* * ? * 1" + - "0-59 0-23 * 1 ?" + matrix: + NODE_VERSION: + - 18 + - 20 + parameters: + color: [red, blue] + provider: + name: aws + region: us-west-2 + accountId: 111111111111 + role: arn:aws:iam::111111111111:role/role + executor: eks + clusterName: sd-build-eks + requires: ~commit + secrets: + - NPM_TOKEN + sourcePaths: + - src/A + - src/AConfig + template: foo/bar@1.0.0 + order: + - install + - test + - other + - echo + steps: + - install: npm install + - test: npm test + - echo: echo $FOO + cache: + pipeline: ["node_modules/", "~/.sbt"] + event: ["target/generated-intermediate-resouce/*"] + job: + build: ["target/some-artifact.zip"] + publish-preview: ["target/some-artifact.zip"] + test: [] + subscribe: + scmUrls: + - git@github.com:foo/bar.git#master: [~commit, ~tags, ~release] + annotations: + foo: a + bar: b + parameters: + color: [red, blue]