forked from cdklabs/cdk-cicd-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.projenrc.ts
344 lines (289 loc) · 10 KB
/
.projenrc.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import * as pj from 'projen';
import { yarn } from 'cdklabs-projen-project-types';
import { Eslint } from 'projen/lib/javascript';
import { JSIIComponent } from './projenrc/jsiicomponent';
const repositoryUrl = 'https://github.com/cdklabs/cdk-cicd-wrapper.git';
const eslintDeps = [
'eslint@^8',
'@typescript-eslint/eslint-plugin@^7',
'@typescript-eslint/parser@^7',
'@typescript-eslint/typescript-estree@^7',
];
const workflowRunsOn = ['ubuntu-latest'];
const cdkVersion = '2.149.0';
const cdkNagVersion = '2.28.0';
const constructsVersion = '10.0.0';
const authorName = 'CDK CI/CD Wrapper Team';
const root = new yarn.Monorepo({
name: 'cdk-cicd-wrapper',
authorName,
description: 'This repository contains the infrastructure as code to wrap your AWS CDK project with CI/CD around it.',
repository: repositoryUrl,
homepage: repositoryUrl,
keywords: ['cli', 'aws-cdk', 'awscdk', 'aws', 'ci-cd-boot', 'ci-cd', 'vanilla-pipeline'],
projenrcTs: true,
defaultReleaseBranch: 'main',
devDeps: [
'cdklabs-projen-project-types',
'node-fetch@^2',
'eslint@^8',
'@typescript-eslint/eslint-plugin@^7',
'@typescript-eslint/parser@^7',
'@typescript-eslint/typescript-estree@^7',
],
buildWorkflow: true,
clobber: true,
autoMerge: true,
vscode: false,
prettier: true,
prettierOptions: {
settings: {
singleQuote: true,
semi: true,
trailingComma: pj.javascript.TrailingComma.ALL,
printWidth: 120,
},
},
workflowRunsOn,
pullRequestTemplate: true,
autoApproveOptions: {
allowedUsernames: ['aws-cdk-automation', 'dependabot[bot]'],
},
release: true,
releaseOptions: {
publishToNpm: true,
releaseTrigger: pj.release.ReleaseTrigger.continuous({
paths: ['packages/*', 'package.json'],
}),
},
githubOptions: {
pullRequestLintOptions: {
semanticTitleOptions: {
types: ['feat', 'fix', 'chore', 'refactor'],
},
},
mergify: false,
},
prerelease: 'alpha',
stability: 'experimental',
gitignore: [
'docs/build',
'docs/dist',
'docs/site',
'.DS_Store',
'junit-reports',
'.npmrc',
'development',
'samples/**/package-lock.json', // ignore lock files
'.devbox',
'.task',
'node_modules',
'.env',
'.env.*',
'.venv',
],
});
//============================================
//
// CI/CD Wrapper package
//
//============================================
const pipeline = new yarn.TypeScriptWorkspace({
parent: root,
name: '@cdklabs/cdk-cicd-wrapper',
authorName,
description: 'This repository contains the infrastructure as code to wrap your AWS CDK project with CI/CD around it.',
keywords: ['cli', 'aws-cdk', 'awscdk', 'aws', 'ci-cd-boot', 'ci-cd', 'vanilla-pipeline'],
releasableCommits: pj.ReleasableCommits.featuresAndFixes('.'),
devDeps: [
'eslint@^8',
`@aws-cdk/integ-runner@${cdkVersion}-alpha.0`,
`@aws-cdk/integ-tests-alpha@${cdkVersion}-alpha.0`,
'@typescript-eslint/eslint-plugin@^7',
'@typescript-eslint/parser@^7',
'@typescript-eslint/typescript-estree@^7',
],
peerDeps: [`cdk-nag@^${cdkNagVersion}`, `aws-cdk-lib@^${cdkVersion}`, `constructs@^${constructsVersion}`],
bundledDeps: ['@cloudcomponents/cdk-pull-request-approval-rule', '@cloudcomponents/cdk-pull-request-check', 'yaml'],
deps: [`cdk-pipelines-github`],
jest: true,
disableTsconfig: true,
});
// Keep the projen module as optional dependency, while we can leverage it in our samples
Eslint.of(pipeline)?.addRules({
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: ['**/test/**', '**/build-tools/**', '**/projen/**'],
optionalDependencies: false,
peerDependencies: true,
},
],
});
const packageBasename = 'cdk-cicd-wrapper';
new JSIIComponent(pipeline, {
publishToPypi: {
distName: `cdklabs.${packageBasename}`,
module: `cdklabs.${changeDelimiter(packageBasename, '_')}`,
},
publishToMaven: {
javaPackage: `io.github.cdklabs.${changeDelimiter(packageBasename, '.')}`,
mavenGroupId: `io.github.cdklabs`,
mavenArtifactId: packageBasename,
mavenEndpoint: 'https://s01.oss.sonatype.org',
},
publishToNuget: {
dotNetNamespace: `${upperCaseName('cdklabs')}.${upperCaseName(packageBasename)}`,
packageId: `${upperCaseName('cdklabs')}.${upperCaseName(packageBasename)}`,
},
});
root.addGitIgnore(pipeline.workspaceDirectory + '/tsconfig.json');
// Copy non TS sources to the package
pipeline.addDevDeps('copyfiles');
pipeline.addDevDeps(...eslintDeps);
pipeline.tasks
.tryFind('post-compile')!
.exec('copyfiles -u 1 -E src/**/*.py src/**/Pipfile src/**/Pipfile.lock src/projen/Taskfile.yaml lib');
pipeline.addTask('integ', {
description: 'Run integration snapshot tests',
exec: 'yarn integ-runner --language typescript',
receiveArgs: true,
});
pipeline.addTask('integ:update', {
description: 'Run and update integration snapshot tests',
exec: 'yarn integ-runner --language typescript --update-on-failed',
receiveArgs: true,
});
root.addTask('integ', {
exec: 'yarn workspace @cdklabs/cdk-cicd-wrapper run integ',
receiveArgs: true,
});
// Copy bundle dependencies to the package
const postCompile = pipeline.tasks.tryFind('post-compile')!;
postCompile.exec("export DEP='@cloudcomponents';cp -rf ../../../node_modules/$DEP ./node_modules/ 2>/dev/null;");
postCompile.exec("export DEP='yaml';cp -rf ../../../node_modules/$DEP ./node_modules/ 2>/dev/null;");
//============================================
//
// CLI package
//
//============================================
const cli = new yarn.TypeScriptWorkspace({
parent: root,
name: '@cdklabs/cdk-cicd-wrapper-cli',
description: 'This repository contains the infrastructure as code to wrap your AWS CDK project with CI/CD around it.',
keywords: ['cli', 'aws-cdk', 'awscdk', 'aws', 'ci-cd-boot', 'ci-cd', 'vanilla-pipeline'],
projenrcTs: true,
bin: {
'cdk-cicd': './bin/cdk-cicd',
},
deps: [
'yargs',
'@types/yargs',
'[email protected]', // globby version 12+ only support ESM
'fs-extra',
'@types/fs-extra',
'csv',
'@aws-sdk/client-s3',
'@aws-sdk/credential-providers',
'tslog',
],
jest: false,
});
// Don't need to include the TypeScript source files in the tarball; the transpiled JS files are sufficient.
cli.addPackageIgnore('*.ts');
cli.addDevDeps(...eslintDeps);
const cliExec = cli.addTask('cli-exec');
cliExec.spawn(cli.tasks.tryFind('compile')!);
cliExec.exec('./packages/@cdklabs/cdk-cicd-wrapper-cli/bin/cdk-cicd', { receiveArgs: true, cwd: '../../..' });
//============================================
//
// Projen package
//
//============================================
const projenModule = new yarn.TypeScriptWorkspace({
parent: root,
name: '@cdklabs/cdk-cicd-wrapper-projen',
description: 'This repository contains the projen support for the project',
projenrcTs: true,
deps: ['projen'],
jest: false,
});
projenModule.addDevDeps(...eslintDeps);
//============================================
//
// Repository level configurations
//
//============================================
const lint = root.addTask('lint', {
description: 'Lint all code',
});
lint.spawn(root.tasks.tryFind('fmt')!);
lint.exec('yarn workspaces run eslint');
const validate = root.addTask('validate', {
description: 'Validate the lock files',
});
validate.exec('yarn workspace @cdklabs/cdk-cicd-wrapper-cli run cli-exec validate', { receiveArgs: true });
const validateFix = root.addTask('validate:fix', {
description: 'Fixes the lock files',
});
validateFix.exec('yarn workspace @cdklabs/cdk-cicd-wrapper-cli run cli-exec validate --fix', { receiveArgs: true });
const license = root.addTask('license', {
description: 'Notice file checking and generation',
});
license.exec('yarn workspace @cdklabs/cdk-cicd-wrapper-cli run cli-exec license', { receiveArgs: true });
// upgrade
const upgrade = root.tasks.tryFind('upgrade')!;
upgrade.spawn(license, { args: ['--fix'] });
upgrade.spawn(validate, { args: ['--fix'] });
const checkDependencies = root.addTask('check-dependencies', {
description: 'Notice file checking and generation',
});
checkDependencies.exec('yarn workspace @cdklabs/cdk-cicd-wrapper-cli run cli-exec check-dependencies', {
receiveArgs: true,
});
const securityScan = root.addTask('security-scan', {
description: 'Notice file checking and generation',
});
securityScan.exec(
'yarn workspace @cdklabs/cdk-cicd-wrapper-cli run cli-exec security-scan --bandit --semgrep --shellcheck --ci',
{ receiveArgs: true, condition: '[ -n "$CI" ]' },
);
securityScan.exec(
'yarn workspace @cdklabs/cdk-cicd-wrapper-cli run cli-exec security-scan --bandit --semgrep --shellcheck',
{ receiveArgs: true, condition: '[ ! -n "$CI" ]' },
);
const audit = root.addTask('audit');
audit.spawn(checkDependencies);
audit.spawn(securityScan);
audit.spawn(license);
// commitlint
root.package.addDevDeps('@commitlint/cli', '@commitlint/config-conventional');
root.package.file.patch(
pj.JsonPatch.add('/commitlint', {
extends: ['@commitlint/config-conventional'],
}),
);
const commitlint = root.addTask('commitlint');
commitlint.exec('commitlint --edit', { receiveArgs: true });
// husky
root.package.addDevDeps('husky');
const prepare = root.addTask('husky');
prepare.exec('husky', { condition: '[ ! -n "$CI" ]' });
setupAllContributors(root);
pipeline.package.file.patch(pj.JsonPatch.add('/devDependencies/constructs', `^${constructsVersion}`));
root.synth();
function setupAllContributors(project: pj.javascript.NodeProject) {
project.addDevDeps('all-contributors-cli');
project.addTask('contributors:update', {
exec: 'all-contributors check | grep "Missing contributors" -A 1 | tail -n1 | sed -e "s/,//g" | xargs -n1 | grep -v "\\[bot\\]" | grep -v "cdklabs-automation" | grep -v "amazon-auto" | xargs -n1 -I{} all-contributors add {} code',
});
project.npmignore?.exclude('/.all-contributorsrc');
}
function upperCaseName(str: string) {
let words = str.split('-');
words = words.map((w) => w[0].toUpperCase() + w.substring(1));
return words.join('');
}
function changeDelimiter(str: string, delim: string) {
return str.split('-').join(delim);
}