Skip to content

Commit d282b64

Browse files
authored
Merge branch 'main' into merge-back/2.77.0
2 parents 06a0b19 + 2a49fd1 commit d282b64

18 files changed

+425
-422
lines changed

CONTRIBUTING.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,110 @@ $ cd packages/aws-cdk
332332
$ yarn watch & # runs in the background
333333
```
334334

335+
#### Verify your fix by deployment
336+
337+
If your PR updates a specific library, you might want to write a simple CDK application and make sure it synthesizes and
338+
deploys correctly. For example, if you modify files under `packages/aws-cdk-lib/aws-eks`, you can write a simple CDK app in typescript to verify its behavior:
339+
340+
341+
```console
342+
$ cd packages/@aws-cdk-testing/framework-integ/test/aws-eks/test
343+
```
344+
345+
Create a `sample.ts` like this:
346+
347+
```ts
348+
import {
349+
App, Stack,
350+
aws_eks as eks,
351+
aws_ec2 as ec2,
352+
} from 'aws-cdk-lib';
353+
import { getClusterVersionConfig } from './integ-tests-kubernetes-version';
354+
355+
const app = new App();
356+
const env = { region: process.env.CDK_DEFAULT_REGION, account: process.env.CDK_DEFAULT_ACCOUNT };
357+
const stack = new Stack(app, 'my-test-stack', { env });
358+
359+
const cluster = new eks.Cluster(stack, 'Cluster', {
360+
vpc,
361+
...getClusterVersionConfig(stack),
362+
defaultCapacity: 0,
363+
});
364+
```
365+
366+
Run `yarn watch` or `npx tsc --watch` in a separate terminal to compile `sample.ts` to `sample.js`:
367+
368+
```console
369+
$ cd packages/@aws-cdk-testing/framework-integ
370+
$ yarn watch
371+
or
372+
$ npx tsc --watch
373+
```
374+
375+
Make sure you have configured [AWS CLI with AWS Authentication](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_auth) as we will deploy it in our AWS account.
376+
377+
Deploy the sample app:
378+
379+
```console
380+
$ cd packages/@aws-cdk-testing/framework-integ
381+
$ npx cdk -a test/aws-eks/test/sample.js diff
382+
$ npx cdk -a test/aws-eks/test/sample.js deploy
383+
```
384+
385+
This allows you to iterate your development and ensure a minimal sample app would successfully deploy as you expect.
386+
You have the freedom to interact with it just as a common CDK app such as viewing differences with `npx cdk diff`
387+
or pass context variables with `npx cdk deploy -c`. You can rapidly iterate your testing with repeated deployments
388+
by importing existing resource such as existing VPC. This can save a lot of time and help you focus on the core changes.
389+
390+
```ts
391+
const vpc = ec2.Vpc.fromLookup(stack, 'Vpc', { isDefault: true });
392+
```
393+
394+
As this is for testing only, do not commit `sample.ts` and `sample.js` to your PR branch.
395+
396+
Alternatively, you can write this test as a new integration test like `integ.my-test.ts` and deploy it
397+
using `yarn integ --no-clean`. This may be useful when you need to publish a new
398+
integration test:
399+
400+
```console
401+
$ cd packages/@aws-cdk-testing/framework-integ
402+
$ yarn integ test/aws-eks/test/integ.my-test.js --no-clean --update-on-failed
403+
```
404+
405+
After verifying your work with a simple deployment as above, you need to ensure your change can pass all existing
406+
unit tests and integ tests and fix them if necessary.
407+
408+
Run all the unit tests for a specific module(e.g. aws-eks):
409+
410+
```console
411+
$ cd packages/aws-cdk-lib
412+
$ yarn test aws-eks
413+
```
414+
415+
Or run a specific unit test
416+
417+
```console
418+
$ cd packages/aws-cdk-lib
419+
$ npx jest aws-eks/test/name.test.js
420+
```
421+
422+
Run all integ tests for a specific module(e.g. aws-eks):
423+
424+
```console
425+
$ cd packages/@aws-cdk-testing/framework-integ
426+
$ yarn integ --directory test/aws-eks/test
427+
```
428+
429+
Or run a specific integ test:
430+
431+
```console
432+
$ yarn integ --directory test/aws-eks/test/integ.name.js
433+
```
434+
435+
See the [integration test guide](./INTEGRATION_TESTS.md) for a more complete guide on running
436+
CDK integration tests.
437+
438+
335439
### Step 4: Pull Request
336440

337441
* Create a commit with your changes and push them to a

buildspec-pr.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ version: 0.2
22

33
# This buildspec is intended to be used by GitHub PR builds.
44

5+
env:
6+
variables:
7+
PR_BUILD: true
8+
59
phases:
610
install:
711
commands:

packages/@aws-cdk/cfnspec/build-tools/build.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@
66
*/
77

88
import * as path from 'path';
9+
import * as fs from 'fs-extra';
910
import * as md5 from 'md5';
1011
import { massageSpec, normalize } from './massage-spec';;
1112
import { writeSorted, applyPatchSet, applyAndWrite } from './patch-set';
13+
import { validateSpecificationEvolution } from './validate-evolution';
1214
import { schema } from '../lib';
1315

1416
async function main() {
1517
const inputDir = path.join(process.cwd(), 'spec-source');
1618
const outDir = path.join(process.cwd(), 'spec');
1719

18-
await generateResourceSpecification(inputDir, path.join(outDir, 'specification.json'));
20+
// If this is a PR build check the spec for evolution (this is set in buildspec-pr.yaml)
21+
const outputFile = path.join(outDir, 'specification.json');
22+
if (process.env.CODEBUILD_WEBHOOK_TRIGGER?.startsWith('pr/')) {
23+
await validateSpecificationEvolution(async () => {
24+
await generateResourceSpecification(inputDir, outputFile);
25+
return fs.readJson(outputFile);
26+
});
27+
} else {
28+
await generateResourceSpecification(inputDir, outputFile);
29+
}
30+
1931
await applyAndWrite(path.join(outDir, 'cfn-lint.json'), path.join(inputDir, 'cfn-lint'));
2032
await applyAndWrite(path.join(outDir, 'cfn-docs.json'), path.join(inputDir, 'cfn-docs'));
2133
}

0 commit comments

Comments
 (0)