Skip to content

Commit

Permalink
feat(aws-codepipeline): switch to webhooks instead of polling by defa…
Browse files Browse the repository at this point in the history
…ult for the GitHub (#1074)
  • Loading branch information
skinny85 authored and Elad Ben-Israel committed Nov 19, 2018
1 parent c531c84 commit 0f14de8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/app-delivery/test/integ.cicd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const source = new code.GitHubSourceAction(stack, 'GitHub', {
owner: 'awslabs',
repo: 'aws-cdk',
oauthToken: new cdk.Secret('DummyToken'),
pollForSourceChanges: true,
});
new cicd.PipelineDeployStackAction(stack, 'DeployStack', {
stage: pipeline.addStage('Deploy'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,13 @@ function _stackArn(stackName: string): string {
}

class PipelineDouble implements cpapi.IPipeline {
public readonly pipelineName: string;
public readonly pipelineArn: string;
public readonly role: iam.Role;

constructor({ pipelineName, role }: { pipelineName?: string, role: iam.Role }) {
this.pipelineArn = cdk.ArnUtils.fromComponents({ service: 'codepipeline', resource: 'pipeline', resourceName: pipelineName || 'TestPipeline' });
this.pipelineName = pipelineName || 'TestPipeline';
this.pipelineArn = cdk.ArnUtils.fromComponents({ service: 'codepipeline', resource: 'pipeline', resourceName: this.pipelineName });
this.role = role;
}

Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-codepipeline-api/lib/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export interface IInternalStage {
* so this interface can be used as a Target for CloudWatch Events.
*/
export interface IPipeline extends events.IEventRuleTarget {
/**
* The name of the Pipeline.
*/
readonly pipelineName: string;

/**
* The ARN of the Pipeline.
*/
Expand Down
27 changes: 24 additions & 3 deletions packages/@aws-cdk/aws-codepipeline/lib/github-source-action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import actions = require('@aws-cdk/aws-codepipeline-api');
import cdk = require('@aws-cdk/cdk');
import { cloudformation } from './codepipeline.generated';

/**
* Construction properties of the {@link GitHubSourceAction GitHub source action}.
Expand Down Expand Up @@ -44,9 +45,10 @@ export interface GitHubSourceActionProps extends actions.CommonActionProps,
oauthToken: cdk.Secret;

/**
* Whether or not AWS CodePipeline should poll for source changes
* Whether AWS CodePipeline should poll for source changes.
* If this is `false`, the Pipeline will use a webhook to detect source changes instead.
*
* @default true
* @default false
*/
pollForSourceChanges?: boolean;
}
Expand All @@ -66,9 +68,28 @@ export class GitHubSourceAction extends actions.SourceAction {
Repo: props.repo,
Branch: props.branch || "master",
OAuthToken: props.oauthToken,
PollForSourceChanges: props.pollForSourceChanges || true
PollForSourceChanges: props.pollForSourceChanges || false,
},
outputArtifactName: props.outputArtifactName
});

if (!props.pollForSourceChanges) {
new cloudformation.WebhookResource(this, 'WebhookResource', {
authentication: 'GITHUB_HMAC',
authenticationConfiguration: {
secretToken: props.oauthToken,
},
filters: [
{
jsonPath: '$.ref',
matchEquals: 'refs/heads/{Branch}',
},
],
targetAction: this.id,
targetPipeline: props.stage.pipeline.pipelineName,
targetPipelineVersion: 1,
registerWithThirdParty: true,
});
}
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codepipeline/test/test.pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export = {
"OAuthToken": {
"Ref": "GitHubTokenParameterBB166B9D"
},
"PollForSourceChanges": true
"PollForSourceChanges": false
},
"InputArtifacts": [],
"Name": "GH",
Expand Down

0 comments on commit 0f14de8

Please sign in to comment.