-
Notifications
You must be signed in to change notification settings - Fork 66
/
index.ts
122 lines (105 loc) · 3.57 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { CfnOutput } from "aws-cdk-lib";
import { Repository } from "aws-cdk-lib/aws-codecommit";
import {
CodePipeline,
CodePipelineProps,
CodePipelineSource,
ShellStep,
ShellStepProps,
} from "aws-cdk-lib/pipelines";
import { Construct } from "constructs";
const DEFAULT_BRANCH_NAME = "mainline";
/**
* Properties to configure the PDKPipeline.
*
* Note: Due to limitations with JSII and generic support it should be noted that
* the synth, synthShellStepPartialProps.input and
* synthShellStepPartialProps.primaryOutputDirectory properties will be ignored
* if passed in to this construct.
*
* synthShellStepPartialProps.commands is marked as a required field, however
* if you pass in [] the default commands of this construct will be retained.
*/
export interface PDKPipelineProps extends CodePipelineProps {
/**
* Enables a build job to trigger on PR merges to the defaultBranchName. This
* will automatically build the codebase and add an Approval to the PR on
* successful build.
*
* @default true
*/
readonly prBuildChecker?: boolean;
/**
* Name of the CodeCommit repository to create.
*/
readonly repositoryName: string;
/**
* Output directory for cdk synthesized artifacts i.e: packages/infra/cdk.out.
*/
readonly primarySynthDirectory: string;
/**
* PDKPipeline by default assumes a NX Monorepo structure for it's codebase and
* uses sane defaults for the install and run commands. To override these defaults
* and/or provide additional inputs, specify env settings, etc you can provide
* a partial ShellStepProps.
*/
readonly synthShellStepPartialProps?: ShellStepProps;
/**
* Branch to trigger the pipeline execution.
*
* @default mainline
*/
readonly defaultBranchName?: string;
}
/**
* An extension to CodePipeline which configures sane defaults for a NX Monorepo
* codebase. In addition to this, it also creates a CodeCommit repository with
* automated PR builds and approvals.
*/
export class PDKPipeline extends CodePipeline {
readonly codeRepository: Repository;
public constructor(scope: Construct, id: string, props: PDKPipelineProps) {
const codeRepository = new Repository(scope, "CodeRepository", {
repositoryName: props.repositoryName,
});
// TODO: Implement prBuildChecker
// ignore input and primaryOutputDirectory
const {
input,
primaryOutputDirectory,
commands,
...synthShellStepPartialProps
} = props.synthShellStepPartialProps || {};
const codePipelineProps: CodePipelineProps = {
...props,
synth: new ShellStep("Synth", {
input: CodePipelineSource.codeCommit(
codeRepository,
props.defaultBranchName || DEFAULT_BRANCH_NAME
),
installCommands: ["yarn install --frozen-lockfile"],
commands:
commands && commands.length > 0
? commands
: ["npx nx run-many --target=build --all"],
primaryOutputDirectory: props.primarySynthDirectory,
...(synthShellStepPartialProps || {}),
}),
};
super(scope, id, codePipelineProps);
this.codeRepository = codeRepository;
new CfnOutput(scope, "CodeRepositoryGRCUrl", {
exportName: "CodeRepositoryGRCUrl",
value: this.codeRepository.repositoryCloneUrlGrc,
});
}
buildPipeline() {
super.buildPipeline();
new CfnOutput(this, "SynthBuildProjectArn", {
exportName: "SynthBuildProjectArn",
value: this.synthProject.projectArn,
});
}
}