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

feat(aws-codepipeline): don't poll by default in GitHubSourceAction #1074

Merged
merged 1 commit into from
Nov 19, 2018
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
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
skinny85 marked this conversation as resolved.
Show resolved Hide resolved
*/
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