From 1d8310fb36a99064b89c4c19974150719d660c45 Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 23 Apr 2019 10:25:12 +0200 Subject: [PATCH] Implement requested changes --- .../@aws-cdk/app-delivery/test/integ.cicd.ts | 4 +- .../aws-codepipeline-actions/README.md | 2 +- .../lib/github/source-action.ts | 17 ++- .../test/test.pipeline.ts | 116 +++--------------- 4 files changed, 33 insertions(+), 106 deletions(-) diff --git a/packages/@aws-cdk/app-delivery/test/integ.cicd.ts b/packages/@aws-cdk/app-delivery/test/integ.cicd.ts index f694086d116ac..e0263b6c3633d 100644 --- a/packages/@aws-cdk/app-delivery/test/integ.cicd.ts +++ b/packages/@aws-cdk/app-delivery/test/integ.cicd.ts @@ -19,8 +19,8 @@ const source = new cpactions.GitHubSourceAction({ owner: 'awslabs', repo: 'aws-cdk', oauthToken: cdk.SecretValue.plainText('DummyToken'), - trigger: cpactions.TriggerType.Poll, - outputArtifactName: 'Artifact_CICDGitHubF8BA7ADD', + trigger: cpactions.GitHubTrigger.Poll, + output: sourceOutput, }); pipeline.addStage({ name: 'Source', diff --git a/packages/@aws-cdk/aws-codepipeline-actions/README.md b/packages/@aws-cdk/aws-codepipeline-actions/README.md index bc7e86af8c600..a0a87107ae2a3 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/README.md +++ b/packages/@aws-cdk/aws-codepipeline-actions/README.md @@ -50,7 +50,7 @@ const sourceAction = new codepipeline_actions.GitHubSourceAction({ oauthToken: token.value, output: sourceOutput, branch: 'develop', // default: 'master' - trigger: codepipeline_actions.TriggerType.Poll // default: 'WebHook', 'None' is also possible for no Source trigger + trigger: codepipeline_actions.GitHubTrigger.Poll // default: 'WebHook', 'None' is also possible for no Source trigger }); pipeline.addStage({ name: 'Source', diff --git a/packages/@aws-cdk/aws-codepipeline-actions/lib/github/source-action.ts b/packages/@aws-cdk/aws-codepipeline-actions/lib/github/source-action.ts index 5eae766e51251..51d85c2edd80d 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/lib/github/source-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/lib/github/source-action.ts @@ -2,7 +2,10 @@ import codepipeline = require('@aws-cdk/aws-codepipeline'); import { SecretValue } from '@aws-cdk/cdk'; import { sourceArtifactBounds } from '../common'; -export enum TriggerType { +/** + * If and how the GitHub source action should be triggered + */ +export enum GitHubTrigger { None = 'None', Poll = 'Poll', WebHook = 'WebHook', @@ -47,9 +50,13 @@ export interface GitHubSourceActionProps extends codepipeline.CommonActionProps /** * How AWS CodePipeline should be triggered * - * @default "WebHook" + * With the default value "WebHook", a webhook is created in GitHub that triggers the action + * With "Poll", CodePipeline periodically checks the source for changes + * With "None", the action is not triggered through changes in the source + * + * @default GitHubTrigger.WebHook */ - readonly trigger?: TriggerType; + readonly trigger?: GitHubTrigger; } /** @@ -71,7 +78,7 @@ export class GitHubSourceAction extends codepipeline.Action { Repo: props.repo, Branch: props.branch || "master", OAuthToken: props.oauthToken.toString(), - PollForSourceChanges: (props.trigger && props.trigger === TriggerType.Poll) || false, + PollForSourceChanges: props.trigger === GitHubTrigger.Poll, }, }); @@ -79,7 +86,7 @@ export class GitHubSourceAction extends codepipeline.Action { } protected bind(info: codepipeline.ActionBind): void { - if (!this.props.trigger || this.props.trigger === TriggerType.WebHook) { + if (!this.props.trigger || this.props.trigger === GitHubTrigger.WebHook) { new codepipeline.CfnWebhook(info.scope, 'WebhookResource', { authentication: 'GITHUB_HMAC', authenticationConfiguration: { diff --git a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts index f7fe7b7639a4a..00de8197a20cb 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/test/test.pipeline.ts @@ -80,12 +80,12 @@ export = { new cpactions.GitHubSourceAction({ actionName: 'GH', runOrder: 8, - outputArtifactName: 'A', + output: new codepipeline.Artifact('A'), branch: 'branch', oauthToken: SecretValue.plainText(secret.stringValue), owner: 'foo', repo: 'bar', - trigger: cpactions.TriggerType.Poll + trigger: cpactions.GitHubTrigger.Poll }), ], }); @@ -100,63 +100,23 @@ export = { 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" + "Configuration": { + "PollForSourceChanges": true + }, + "Name": "GH" } - ], - "RunOrder": 8 - } ], "Name": "Source" }, { "Actions": [ - { - "ActionTypeId": { - "Category": "Approval", - "Owner": "AWS", - "Provider": "Manual", - "Version": "1" - }, - "InputArtifacts": [], - "Name": "Boo", - "OutputArtifacts": [], - "RunOrder": 1 - } + { + "Name": "Boo", + } ], "Name": "Two" } @@ -179,12 +139,12 @@ export = { new cpactions.GitHubSourceAction({ actionName: 'GH', runOrder: 8, - outputArtifactName: 'A', + output: new codepipeline.Artifact('A'), branch: 'branch', oauthToken: SecretValue.plainText(secret.stringValue), owner: 'foo', repo: 'bar', - trigger: cpactions.TriggerType.None + trigger: cpactions.GitHubTrigger.None }), ], }); @@ -199,63 +159,23 @@ export = { 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" + "Configuration": { + "PollForSourceChanges": false + }, + "Name": "GH" } - ], - "RunOrder": 8 - } ], "Name": "Source" }, { "Actions": [ - { - "ActionTypeId": { - "Category": "Approval", - "Owner": "AWS", - "Provider": "Manual", - "Version": "1" - }, - "InputArtifacts": [], - "Name": "Boo", - "OutputArtifacts": [], - "RunOrder": 1 - } + { + "Name": "Boo", + } ], "Name": "Two" }