Skip to content

Commit

Permalink
feat(3068): flatten pipeline template (#39)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: eliminating pipeline template shared config
  • Loading branch information
klu909 authored Apr 30, 2024
1 parent 806df32 commit cf1a7cc
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 27 deletions.
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const SCHEMA_CONFIG = require('screwdriver-data-schema').config.template.template;
const SCHEMA_PIPELINE_TEMPLATE = require('screwdriver-data-schema').config.pipelineTemplate.template;
const parser = require('screwdriver-config-parser').parsePipelineTemplate;
const Yaml = require('js-yaml');
const helper = require('./lib/helper');

Expand Down Expand Up @@ -132,11 +132,10 @@ async function parseJobTemplate(yamlString, templateFactory) {
* the given template
*/
async function parsePipelineTemplate(yamlString) {
let configToValidate;
const configToValidate = await loadTemplate(yamlString);

try {
configToValidate = await loadTemplate(yamlString);
const config = await validateTemplateStructure(configToValidate, SCHEMA_PIPELINE_TEMPLATE);
const config = await parser({ yaml: yamlString });

return {
errors: [],
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"@hapi/hoek": "^10.0.1",
"joi": "^17.7.0",
"js-yaml": "^4.1.0",
"screwdriver-data-schema": "^23.0.4"
"screwdriver-data-schema": "^23.0.4",
"screwdriver-config-parser": "^10.0.0"
},
"release": {
"debug": false
Expand Down
168 changes: 149 additions & 19 deletions test/data/valid_full_pipeline_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,159 @@
"description": "template description",
"maintainer": "[email protected]",
"config": {
"jobs": {
"main": {
"steps": [
{
"init": "npm install"
},
{
"test": "npm test"
}
"jobs": {
"main": {
"image": "node:20",
"environment": {
"FOO": "foo"
},
"settings": {
"email": "[email protected]"
},
"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": {
"accountId": 111111111111,
"buildRegion": "",
"clusterName": "sd-build-eks",
"computeType": "BUILD_GENERAL1_SMALL",
"debugSession": false,
"environmentType": "LINUX_CONTAINER",
"executor": "eks",
"executorLogs": false,
"name": "aws",
"privilegedMode": false,
"region": "us-west-2",
"role": "arn:aws:iam::111111111111:role/role"
},
"requires": "~commit",
"secrets": [
"NPM_TOKEN"
],
"sourcePaths": [
"src/A",
"src/AConfig"
],
"template": "foo/[email protected]",
"order": [
"install",
"test",
"other",
"echo"
],
"steps": [
{
"init": "npm install"
},
{
"test": "npm test"
}
]
},
"shared": {
"environment": {
"FOO": "bar"
}
},
"parameters": {
"user": {
"value": "sd-bot",
"description": "User running build"
"test": {
"image": "node:18",
"environment": {
"FOO": "foo"
},
"settings": {
"email": "[email protected]"
},
"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": {
"accountId": 111111111111,
"buildRegion": "",
"clusterName": "sd-build-eks",
"computeType": "BUILD_GENERAL1_SMALL",
"debugSession": false,
"environmentType": "LINUX_CONTAINER",
"executor": "eks",
"executorLogs": false,
"name": "aws",
"privilegedMode": false,
"region": "us-west-2",
"role": "arn:aws:iam::111111111111:role/role"
},
"requires": "~commit",
"secrets": [
"NPM_TOKEN"
],
"sourcePaths": [
"src/A",
"src/AConfig"
],
"template": "foo/[email protected]",
"order": [
"install",
"test",
"other",
"echo"
],
"steps": [
{
"install": "npm install"
},
{
"test": "npm test"
},
{
"echo": "echo $FOO"
}
]
}
},
"parameters": {
"user": {
"value": "sd-bot",
"description": "User running build"
}
}
}
}
}
}
49 changes: 46 additions & 3 deletions test/data/valid_full_pipeline_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,57 @@ version: 1.2.3
description: template description
maintainer: [email protected]
config:
shared:
image: node:20
environment:
FOO: foo
settings:
email: [email protected]
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/[email protected]
order:
- install
- test
- other
- echo
steps:
- install: npm install
- test: npm test
- echo: echo $FOO
jobs:
main:
steps:
- init: npm install
- test: npm test
shared:
environment:
FOO: bar
test:
image: node:18
parameters:
user:
value: sd-bot
Expand Down

0 comments on commit cf1a7cc

Please sign in to comment.