Skip to content

Commit

Permalink
Merge pull request #40 from screwdriver-cd/override
Browse files Browse the repository at this point in the history
feat: support overriding steps for templates
  • Loading branch information
minzcmu authored Jul 11, 2017
2 parents 8749fee + daa3b4a commit ce2d46a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/phase/flatten.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ function merge(newJob, oldJob, fromTemplate) {
mergedSteps.push({ [preStepName]: oldSteps[preStepName] });
}

mergedSteps.push(newJob.steps[i]);
// override step
if (oldSteps[stepName]) {
mergedSteps.push({ [stepName]: oldSteps[stepName] });
} else {
mergedSteps.push(newJob.steps[i]);
}

// add post-step
if (oldSteps[postStepName]) {
Expand Down
36 changes: 36 additions & 0 deletions test/data/basic-job-with-template-override-steps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"annotations": {},
"jobs": {
"main": [{
"annotations": {},
"image": "node:4",
"commands": [
{
"name": "install",
"command": "npm install"
},
{
"name": "pretest",
"command": "echo pre-test"
},
{
"name": "test",
"command": "echo 'my job is overriding this step'"
}
],
"environment": {
"FOO": "from template",
"BAR": "foo"
},
"secrets": [
"GIT_KEY"
],
"settings": {
"email": "[email protected]"
}
}]
},
"workflow": [
"main"
]
}
6 changes: 6 additions & 0 deletions test/data/basic-job-with-template-override-steps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
jobs:
main:
template: [email protected]
steps:
- pretest: echo pre-test
- test: echo 'my job is overriding this step'
6 changes: 6 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ describe('config parser', () => {
data, JSON.parse(loadData('basic-job-with-template-wrapped-steps.json'))))
);

it('flattens templates with job steps ', () =>
parser(loadData('basic-job-with-template-override-steps.yaml'), templateFactoryMock)
.then(data => assert.deepEqual(
data, JSON.parse(loadData('basic-job-with-template-override-steps.json'))))
);

it('returns error if template does not exist', () => {
templateFactoryMock.getTemplate.withArgs(firstTemplateConfig).resolves(null);

Expand Down

0 comments on commit ce2d46a

Please sign in to comment.