Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(codepipeline): correctly validate Artifacts used by Actions in th… #2558

Merged
merged 1 commit into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ export class Pipeline extends PipelineBase {
for (const stage of this.stages) {
const sortedActions = stage.actions.sort((a1, a2) => a1.runOrder - a2.runOrder);

// start with inputs
for (const action of sortedActions) {
// start with inputs
const inputArtifacts = action.inputs;
for (const inputArtifact of inputArtifacts) {
if (!inputArtifact.artifactName) {
Expand All @@ -508,10 +508,8 @@ export class Pipeline extends PipelineBase {
ret.push(`Artifact '${inputArtifact.artifactName}' was used as input before being used as output`);
}
}
}

// then process outputs by adding them to the Set
for (const action of sortedActions) {
// then process outputs by adding them to the Set
const outputArtifacts = action.outputs;
for (const outputArtifact of outputArtifacts) {
// output Artifacts always have a name set
Expand Down
51 changes: 50 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/test/test.artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { expect, haveResourceLike } from '@aws-cdk/assert';
import { expect, haveResourceLike } from '@aws-cdk/assert';
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
import codepipeline = require('../lib');
Expand Down Expand Up @@ -123,6 +123,55 @@ export = {

test.done();
},

"an Action's output can be used as input for an Action in the same Stage with a higher runOrder"(test: Test) {
const stack = new cdk.Stack();

const sourceOutput1 = new codepipeline.Artifact('sourceOutput1');
const buildOutput1 = new codepipeline.Artifact('buildOutput1');
const sourceOutput2 = new codepipeline.Artifact('sourceOutput2');

new codepipeline.Pipeline(stack, 'Pipeline', {
stages: [
{
name: 'Source',
actions: [
new FakeSourceAction({
actionName: 'source1',
output: sourceOutput1,
}),
new FakeSourceAction({
actionName: 'source2',
output: sourceOutput2,
}),
],
},
{
name: 'Build',
actions: [
new FakeBuildAction({
actionName: 'build1',
input: sourceOutput1,
output: buildOutput1,
}),
new FakeBuildAction({
actionName: 'build2',
input: sourceOutput2,
extraInputs: [buildOutput1],
output: new codepipeline.Artifact('buildOutput2'),
runOrder: 2,
}),
],
},
],
});

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's up here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug is a validation error, so the expect is used only to trigger validation. This test fails without the production code changes.

}));

test.done();
},
},
};

Expand Down