Skip to content

Commit

Permalink
[BREAKING] Move the S3 Source Action out of the codepipeline package,
Browse files Browse the repository at this point in the history
and rename it.

This is in order to make it consistent with the other AWS service Actions.
  • Loading branch information
skinny85 committed Aug 2, 2018
1 parent e7508a7 commit 52e9d8f
Show file tree
Hide file tree
Showing 15 changed files with 808 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import codebuild = require('@aws-cdk/aws-codebuild');
import codecommit = require('@aws-cdk/aws-codecommit');
import codecommitPipeline = require('@aws-cdk/aws-codecommit-codepipeline');
import codepipeline = require('@aws-cdk/aws-codepipeline');
import s3 = require('@aws-cdk/aws-s3');
import sns = require('@aws-cdk/aws-sns');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
Expand Down Expand Up @@ -132,11 +131,13 @@ export = {

const pipeline = new codepipeline.Pipeline(stack, 'PL');

new codepipeline.AmazonS3Source(new codepipeline.Stage(pipeline, 'S1'), 'A1', {
artifactName: 'Artifact',
bucket: new s3.Bucket(stack, 'Bucket'),
bucketKey: 'Key'
const repo = new codecommit.Repository(stack, 'MyRepo', { repositoryName: 'my-repo' });
const sourceStage = new codepipeline.Stage(pipeline, 'source');
new codecommitPipeline.PipelineSource(sourceStage, 'source', {
artifactName: 'SourceArtifact',
repository: repo,
});

new codepipeline.ApprovalAction(new codepipeline.Stage(pipeline, 'S2'), 'A2');

pipeline.onStateChange('OnStateChange', topic, {
Expand Down
55 changes: 3 additions & 52 deletions packages/@aws-cdk/aws-codepipeline/lib/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import events = require('@aws-cdk/aws-events');
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import { Artifact } from './artifact';
import { cloudformation } from './codepipeline.generated';
Expand Down Expand Up @@ -241,8 +240,9 @@ export interface SourceProps {
}

/**
* Low level class for source actions.
* It is recommended that concrete types are used instead, such as {@link AmazonS3Source} or
* Low level class for source Actions.
* It is recommended that concrete types are used instead,
* such as {@link s3pipeline.SourceAction} or
* {@link codecommit.PipelineSource}.
*/
export abstract class Source extends Action {
Expand All @@ -262,55 +262,6 @@ export abstract class Source extends Action {
}
}

/**
* Construction properties of the {@link AmazonS3Source S3 source action}
*/
export interface AmazonS3SourceProps {
/**
* The name of the source's output artifact. Output artifacts are used by CodePipeline as
* inputs into other actions.
*/
artifactName: string;

/**
* The Amazon S3 bucket that stores the source code
*/
bucket: s3.BucketRef;

/**
* The key within the S3 bucket that stores the source code
*/
bucketKey: string;

// TODO: use CloudWatch events instead
/**
* Whether or not AWS CodePipeline should poll for source changes
*
* @default true
*/
pollForSourceChanges?: boolean;
}

/**
* Source that is provided by a specific Amazon S3 object
*/
export class AmazonS3Source extends Source {
constructor(parent: Stage, name: string, props: AmazonS3SourceProps) {
super(parent, name, {
provider: 'S3',
configuration: {
S3Bucket: props.bucket.bucketName,
S3ObjectKey: props.bucketKey,
PollForSourceChanges: props.pollForSourceChanges || true
},
artifactName: props.artifactName
});

// pipeline needs permissions to read from the S3 bucket
props.bucket.grantRead(parent.pipeline.role);
}
}

/**
* Construction properties of the {@link GitHubSource GitHub source action}
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import s3 = require('@aws-cdk/aws-s3');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
import { AmazonS3Source } from '../lib/actions';
import { GitHubSource } from '../lib/actions';
import { Pipeline } from '../lib/pipeline';
import { Stage } from '../lib/stage';
import { validateName } from '../lib/validation';
Expand Down Expand Up @@ -60,16 +59,17 @@ export = {
const firstStage = new Stage(pipeline, 'FirstStage');
const secondStage = new Stage(pipeline, 'SecondStage');

const bucket = new s3.Bucket(stack, 'PipelineBucket');
new AmazonS3Source(firstStage, 'FirstAction', {
new GitHubSource(firstStage, 'FirstAction', {
artifactName: 'FirstArtifact',
bucket,
bucketKey: 'key',
owner: 'awslabs',
repo: 'aws-cdk',
oauthToken: new cdk.Secret('not-secret'),
});
new AmazonS3Source(secondStage, 'SecondAction', {
new GitHubSource(secondStage, 'SecondAction', {
artifactName: 'SecondAction',
bucket,
bucketKey: 'key',
owner: 'awslabs',
repo: 'aws-cdk',
oauthToken: new cdk.Secret('not-secret'),
});

test.deepEqual(pipeline.validate().length, 1);
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-lambda-codepipeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "^0.8.0",
"@aws-cdk/aws-s3": "^0.8.0",
"@aws-cdk/aws-s3-codepipeline": "^0.8.0",
"cdk-build-tools": "^0.8.0",
"cdk-integ-tools": "^0.8.0",
"pkglint": "^0.8.0"
},
"dependencies": {
"@aws-cdk/aws-codepipeline": "^0.8.0",
"@aws-cdk/aws-lambda": "^0.8.0",
"@aws-cdk/aws-s3": "^0.8.0",
"@aws-cdk/cdk": "^0.8.0"
},
"homepage": "https://github.com/awslabs/aws-cdk"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import codepipeline = require('@aws-cdk/aws-codepipeline');
import lambda = require('@aws-cdk/aws-lambda');
import s3 = require('@aws-cdk/aws-s3');
import s3Pipeline = require('@aws-cdk/aws-s3-codepipeline');
import cdk = require('@aws-cdk/cdk');
import lambda_codepipeline = require('../lib');
import lambdaCodepipeline = require('../lib');

const app = new cdk.App(process.argv);

Expand All @@ -14,7 +15,7 @@ const sourceStage = new codepipeline.Stage(pipeline, 'Source');
const bucket = new s3.Bucket(stack, 'PipelineBucket', {
versioned: true,
});
new codepipeline.AmazonS3Source(sourceStage, 'Source', {
new s3Pipeline.SourceAction(sourceStage, 'Source', {
artifactName: 'SourceArtifact',
bucket,
bucketKey: 'key',
Expand All @@ -30,7 +31,7 @@ const lambdaFun = new lambda.Lambda(stack, 'LambdaFun', {
runtime: lambda.LambdaRuntime.NodeJS610,
});
const lambdaStage = new codepipeline.Stage(pipeline, 'Lambda');
new lambda_codepipeline.PipelineInvokeAction(lambdaStage, 'Lambda', {
new lambdaCodepipeline.PipelineInvokeAction(lambdaStage, 'Lambda', {
lambda: lambdaFun,
});

Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-s3-codepipeline/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.js
*.js.map
*.d.ts
tsconfig.json
tslint.json
node_modules
*.generated.ts
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
.nycrc
.LAST_PACKAGE
11 changes: 11 additions & 0 deletions packages/@aws-cdk/aws-s3-codepipeline/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz

dist
.LAST_PACKAGE
.LAST_BUILD
!*.js
Loading

0 comments on commit 52e9d8f

Please sign in to comment.