Skip to content

Commit

Permalink
feat(codepipeline): allow creation of pipelines without source trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderKnape committed Apr 19, 2019
1 parent cab71b6 commit b086c59
Show file tree
Hide file tree
Showing 5 changed files with 1,498 additions and 1,292 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/app-delivery/test/integ.cicd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const source = new cpactions.GitHubSourceAction({
owner: 'awslabs',
repo: 'aws-cdk',
oauthToken: cdk.SecretValue.plainText('DummyToken'),
pollForSourceChanges: true,
trigger: cpactions.TriggerType.Poll,
outputArtifactName: 'Artifact_CICDGitHubF8BA7ADD',
});
pipeline.addStage({
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-codepipeline-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const sourceAction = new codepipeline_actions.GitHubSourceAction({
oauthToken: token.value,
outputArtifactName: 'SourceOutput', // this will be the name of the output artifact in the Pipeline
branch: 'develop', // default: 'master'
trigger: codepipeline_actions.TriggerType.Poll // default: 'WebHook', 'None' is also possible for no Source trigger
});
pipeline.addStage({
name: 'Source',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import codepipeline = require('@aws-cdk/aws-codepipeline');
import { SecretValue } from '@aws-cdk/cdk';

export enum TriggerType {
None = 'None',
Poll = 'Poll',
WebHook = 'WebHook',
}

/**
* Construction properties of the {@link GitHubSourceAction GitHub source action}.
*/
Expand Down Expand Up @@ -39,12 +45,11 @@ export interface GitHubSourceActionProps extends codepipeline.CommonActionProps
readonly oauthToken: SecretValue;

/**
* Whether AWS CodePipeline should poll for source changes.
* If this is `false`, the Pipeline will use a webhook to detect source changes instead.
* How AWS CodePipeline should be triggered
*
* @default false
* @default "WebHook"
*/
readonly pollForSourceChanges?: boolean;
readonly trigger?: TriggerType;
}

/**
Expand All @@ -63,7 +68,7 @@ export class GitHubSourceAction extends codepipeline.SourceAction {
Repo: props.repo,
Branch: props.branch || "master",
OAuthToken: props.oauthToken.toString(),
PollForSourceChanges: props.pollForSourceChanges || false,
PollForSourceChanges: (props.trigger && props.trigger === TriggerType.Poll) || false,
},
outputArtifactName: props.outputArtifactName
});
Expand All @@ -72,7 +77,7 @@ export class GitHubSourceAction extends codepipeline.SourceAction {
}

protected bind(info: codepipeline.ActionBind): void {
if (!this.props.pollForSourceChanges) {
if (!this.props.trigger || this.props.trigger === TriggerType.WebHook) {
new codepipeline.CfnWebhook(info.scope, 'WebhookResource', {
authentication: 'GITHUB_HMAC',
authenticationConfiguration: {
Expand Down
202 changes: 201 additions & 1 deletion packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, haveResource, haveResourceLike, SynthUtils } from '@aws-cdk/assert';
import { expect, haveResource, haveResourceLike, not, SynthUtils } from '@aws-cdk/assert';
import codebuild = require('@aws-cdk/aws-codebuild');
import codecommit = require('@aws-cdk/aws-codecommit');
import codepipeline = require('@aws-cdk/aws-codepipeline');
Expand Down Expand Up @@ -65,6 +65,204 @@ export = {
test.done();
},

'pipeline with GitHub source with poll trigger'(test: Test) {
const stack = new Stack();

const secret = new CfnParameter(stack, 'GitHubToken', { type: 'String', default: 'my-token' });

const p = new codepipeline.Pipeline(stack, 'P');

p.addStage({
name: 'Source',
actions: [
new cpactions.GitHubSourceAction({
actionName: 'GH',
runOrder: 8,
outputArtifactName: 'A',
branch: 'branch',
oauthToken: SecretValue.plainText(secret.stringValue),
owner: 'foo',
repo: 'bar',
trigger: cpactions.TriggerType.Poll
}),
],
});

p.addStage({
name: 'Two',
actions: [
new cpactions.ManualApprovalAction({ actionName: 'Boo' }),
],
});

expect(stack).to(not(haveResourceLike('AWS::CodePipeline::Webhook')));

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
"ArtifactStore": {
"Location": {
"Ref": "PArtifactsBucket5E711C12"
},
"Type": "S3"
},
"RoleArn": {
"Fn::GetAtt": [
"PRole07BDC907",
"Arn"
]
},
"Stages": [
{
"Actions": [
{
"ActionTypeId": {
"Category": "Source",
"Owner": "ThirdParty",
"Provider": "GitHub",
"Version": "1"
},
"Configuration": {
"Owner": "foo",
"Repo": "bar",
"Branch": "branch",
"OAuthToken": {
"Ref": "GitHubToken"
},
"PollForSourceChanges": true
},
"InputArtifacts": [],
"Name": "GH",
"OutputArtifacts": [
{
"Name": "A"
}
],
"RunOrder": 8
}
],
"Name": "Source"
},
{
"Actions": [
{
"ActionTypeId": {
"Category": "Approval",
"Owner": "AWS",
"Provider": "Manual",
"Version": "1"
},
"InputArtifacts": [],
"Name": "Boo",
"OutputArtifacts": [],
"RunOrder": 1
}
],
"Name": "Two"
}
]
}));

test.done();
},

'pipeline with GitHub source without triggers'(test: Test) {
const stack = new Stack();

const secret = new CfnParameter(stack, 'GitHubToken', { type: 'String', default: 'my-token' });

const p = new codepipeline.Pipeline(stack, 'P');

p.addStage({
name: 'Source',
actions: [
new cpactions.GitHubSourceAction({
actionName: 'GH',
runOrder: 8,
outputArtifactName: 'A',
branch: 'branch',
oauthToken: SecretValue.plainText(secret.stringValue),
owner: 'foo',
repo: 'bar',
trigger: cpactions.TriggerType.None
}),
],
});

p.addStage({
name: 'Two',
actions: [
new cpactions.ManualApprovalAction({ actionName: 'Boo' }),
],
});

expect(stack).to(not(haveResourceLike('AWS::CodePipeline::Webhook')));

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
"ArtifactStore": {
"Location": {
"Ref": "PArtifactsBucket5E711C12"
},
"Type": "S3"
},
"RoleArn": {
"Fn::GetAtt": [
"PRole07BDC907",
"Arn"
]
},
"Stages": [
{
"Actions": [
{
"ActionTypeId": {
"Category": "Source",
"Owner": "ThirdParty",
"Provider": "GitHub",
"Version": "1"
},
"Configuration": {
"Owner": "foo",
"Repo": "bar",
"Branch": "branch",
"OAuthToken": {
"Ref": "GitHubToken"
},
"PollForSourceChanges": false
},
"InputArtifacts": [],
"Name": "GH",
"OutputArtifacts": [
{
"Name": "A"
}
],
"RunOrder": 8
}
],
"Name": "Source"
},
{
"Actions": [
{
"ActionTypeId": {
"Category": "Approval",
"Owner": "AWS",
"Provider": "Manual",
"Version": "1"
},
"InputArtifacts": [],
"Name": "Boo",
"OutputArtifacts": [],
"RunOrder": 1
}
],
"Name": "Two"
}
]
}));

test.done();
},

'github action uses ThirdParty owner'(test: Test) {
const stack = new Stack();

Expand Down Expand Up @@ -94,6 +292,8 @@ export = {
],
});

expect(stack).to(haveResourceLike('AWS::CodePipeline::Webhook'));

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
"ArtifactStore": {
"Location": {
Expand Down
Loading

0 comments on commit b086c59

Please sign in to comment.