Skip to content

Commit

Permalink
feat(auto-build): Support Artifacts for AutoBuild (#1456)
Browse files Browse the repository at this point in the history
Integ test automation will use artifacts, let them be configured on autobuild jobs.

-----

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
comcalvi authored Sep 28, 2023
1 parent 9f315b4 commit 3794fe4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/__tests__/auto-build.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { App, Stack } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { Artifacts } from 'aws-cdk-lib/aws-codebuild';
import { Bucket } from 'aws-cdk-lib/aws-s3';
import { AutoBuild, GitHubRepo } from '../../lib';

let app: App;
Expand Down Expand Up @@ -127,3 +129,27 @@ test('can disable webhooks', () => {
},
});
});

test('can enable artifacts', () => {
new AutoBuild(stack, 'AutoBuild', {
repo: new GitHubRepo({
repository: 'some-repo',
tokenSecretArn: 'arn:aws:secretsmanager:someregion:someaccount:secret:sometoken',
}),
artifacts: Artifacts.s3({
bucket: new Bucket(stack, 'artifactBucket'),
name: 'artifact-name',
}),
});
const template = Template.fromStack(stack);

template.hasResourceProperties('AWS::CodeBuild::Project', {
Artifacts: {
Location: { Ref: 'artifactBucket27548F83' },
Name: 'artifact-name',
NamespaceType: 'BUILD_ID',
Packaging: 'ZIP',
Type: 'S3',
},
});
});
6 changes: 6 additions & 0 deletions lib/auto-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export interface AutoBuildOptions {
*/
readonly buildSpec?: codebuild.BuildSpec;
/* tslint:enable:max-line-length */

/**
* ARTIFACTS
*/
readonly artifacts?: codebuild.IArtifacts;
}

export interface AutoBuildProps extends AutoBuildOptions {
Expand Down Expand Up @@ -112,6 +117,7 @@ export class AutoBuild extends Construct {
environment: createBuildEnvironment(props.environment ?? {}),
badge: props.repo.allowsBadge,
buildSpec: props.buildSpec,
artifacts: props.artifacts,
ssmSessionPermissions: true,
});
this.project.role!.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonElasticContainerRegistryPublicReadOnly'));
Expand Down

0 comments on commit 3794fe4

Please sign in to comment.