Skip to content

Commit b42e742

Browse files
author
Elad Ben-Israel
authoredOct 23, 2018
fix(docs): updates to contribution guide (#997)
Fixed some stale references, reorganized and added some guidelines and tips
1 parent 0b1e7cc commit b42e742

File tree

1 file changed

+165
-147
lines changed

1 file changed

+165
-147
lines changed
 

Diff for: ‎CONTRIBUTING.md

+165-147
Original file line numberDiff line numberDiff line change
@@ -1,211 +1,190 @@
11
# Contributing to the AWS Cloud Development Kit
22

3+
Thanks for your interest in contibuting to the AWS CDK! ❤️
4+
35
This document describes how to set up a development environment and submit
4-
contributions to this project.
6+
your contributions. Please read it carefully and let us know if it's not up-to-date (even better, submit a PR with your corrections ;-)).
57

6-
## Development Workflow
8+
## Pull Requests
79

8-
1. Setup a [Development Environment](#development-environment)
10+
1. If there isn't one already, open an issue describing what you intend to contribute. It's usful to communicate
11+
in advance, because sometimes, someone is already working in this space, so maybe it's worth
12+
collaborating with them instead of duplicating the efforts.
913
1. Work your magic. Here are some guidelines:
1014
* Every change requires a unit test
11-
* Make sure you update [CHANGELOG] under “[Unreleased]” if the feature/bug is
12-
worthy of a mention
13-
* Make sure to indicate both in the [CHANGELOG] and in the commit message if
14-
the change is BREAKING. A good indication that a change is breaking is if
15-
you had to change old tests to “work” after this change.
15+
* If you change APIs, make sure to update the module's README file
1616
* Try to maintain a single feature/bugfix per pull request. It's okay to
1717
introduce a little bit of housekeeping changes along the way, but try to
1818
avoid conflating multiple features. Eventually all these are going to go
1919
into a single commit, so you can use that to frame your scope.
20-
2. Push to a fork or to a branch (naming convention: `<user>/<feature-bug-name>`)
21-
3. Submit a Pull Requests on GitHub. When authoring your pull request
22-
description:
23-
* Think about your code reviewers and what information they need in order to
24-
have fun with your changes. If it's a big commit (hopefully not), try to
25-
provide some good entry points so it will be easier to follow.
26-
* Ideally, associate with an issue (`fixes #<issue>`), which describes more
27-
details about motivation and the design process.
20+
1. Create a commit with the proposed change changes:
21+
* Commit title and message (and PR title and description) must adhere to [conventionalcommits].
22+
* The title must begin with `feat(module): title`, `fix(module): title`,
23+
`reactor(module): title` or `chore(module): title`.
24+
* Title should be lowercase.
25+
* No period at the end of the title.
26+
* Commit message should describe _motivation_. Think about your code reviewers and what
27+
information they need in order to understand what you did. If it's a big commit (hopefully not),
28+
try to provide some good entry points so it will be easier to follow.
29+
* Commit message should indicate which issues are fixed: `fixes #<issue>` or `closes #<issue>`.
2830
* Shout out to collaborators.
2931
* If not obvious (i.e. from unit tests), describe how you verified that your
3032
change works.
31-
4. Assign the PR for a review to the "awslabs/aws-cdk" team.
33+
* If this commit includes a breaking change, the commit message must end with a
34+
a single pragraph
35+
`BREAKING CHANGE: description of what broke and how to achieve this beahvior now`.
36+
2. Push to a fork or to a branch (naming convention: `<user>/<feature-bug-name>`)
37+
3. Submit a Pull Requests on GitHub and assign the PR for a review to the "awslabs/aws-cdk" team.
3238
5. Discuss review comments and iterate until you get at least one “Approve”. When
3339
iterating, push new commits to the same branch. Usually all these are going
3440
to be squashed when you merge to master. The commit messages should be hints
3541
for you when you finalize your merge commit message.
42+
7. Make sure to update the PR title/description if things change. The PR title/description are going
43+
to be used as the commit title/message and will appear in the CHANGELOG, so maintain them all
44+
the way throughout the process.
3645
6. Make sure your PR builds successfully (we have CodeBuild setup to
3746
automatically build all PRs)
38-
7. Once approved and tested, squash-merge to master __via GitHub__. This is your
39-
opportunity to author a beautiful commit message which describes __the
40-
motivation__ and __design considerations__ of your change. Here are some
41-
[tips](https://chris.beams.io/posts/git-commit/#separate) from Chris Beams.
47+
7. Once approved and tested, a maintainer will squash-merge to master and will use your PR
48+
title/description as the commit message.
4249

43-
## Development Environment
50+
## Tools
4451

45-
This is a monorepo which uses [lerna](https://github.com/lerna/lerna).
52+
The CDK is a big project, and, at the moment, all of the CDK modules are mastered in a single monolithic
53+
repository (uses [lerna](https://github.com/lerna/lerna)). There are pros and cons to this approach,
54+
and it's especially valuable to maintain integrity in the early stage of thr project where things constantly change across the stack. In the future we believe many of these modules will be extracted to their own repositories.
4655

47-
The CDK depends on [jsii](https://github.com/awslabs/jsii), which is still not
48-
published to npm. Therefore, the jsii tarballs are checked-in to this repository
49-
under `./local-npm` and the install script will install them in the repo-global
50-
`node_modules` directory.
56+
Another complexity is that the CDK is packaged using [jsii](https://github.com/awslabs/jsii) to multiple
57+
programming languages. This means that when a full build is complete, there will be a version of each
58+
module for each supported language.
5159

52-
### Prerequisites
60+
However, in many cases, you can probably get away with just building a portion of the
61+
project, based on areas that you want to work on.
5362

54-
Since this repo produces artifacts for multiple programming languages using
55-
__jsii__, it relies on the following toolchains:
63+
### Main build scripts
5664

57-
- [Node.js 8.11.0](https://nodejs.org/download/release/v8.11.0/)
58-
- [Java OpenJDK 8](http://openjdk.java.net/install/)
59-
- [.NET Core 2.0](https://www.microsoft.com/net/download)
60-
- [Python 3.6.5](https://www.python.org/downloads/release/python-365/)
61-
- [Ruby 2.5.1](https://www.ruby-lang.org/en/news/2018/03/28/ruby-2-5-1-released/)
65+
The build process is divided into stages, so you can invoke them as needed:
6266

63-
When building on CodeBuild, these toolchains are all included in the
64-
[superchain](https://github.com/awslabs/superchain) docker image. This image can
65-
also be used locally as follows:
67+
- __`install.sh`__: installs all external dependencies and symlinks internal dependencies (using `lerna link`).
68+
- __`build.sh`__: runs `npm build` and `npm test` in all modules (in topological order).
69+
- __`pack.sh`__: packages all modules to all supported languages and produces a `dist/` directory
70+
with all the outputs (running this script requires that you installed the [toolchains](#Toolchains)
71+
for all target languages on your system).
6672

67-
```shell
68-
eval $(aws ecr get-login --no-include-email)
69-
IMAGE=260708760616.dkr.ecr.us-east-1.amazonaws.com/superchain:latest
70-
docker pull ${IMAGE}
71-
docker run --net=host -it -v $PWD:$PWD -w $PWD ${IMAGE}
72-
```
73-
74-
This will get you into an interactive docker shell. You can then run
75-
`./install.sh` and `./build.sh` as described below.
76-
77-
Also install the [git-secrets](https://github.com/awslabs/git-secrets) tool
78-
and activate it on your working copy of the `aws-cdk` repository.
73+
### Partial build tools
7974

80-
### Bootstrapping
75+
There are also two useful scripts in the `scripts` directory that can help you build part of the repo:
8176

82-
1. Clone this repository (or run `git clean -fdx` to clean up all build artifacts).
83-
2. Run `./install.sh` - this will install all repo-level dependencies, including
84-
`lerna` and the unpublished modules from local-npm.
85-
3. Run `./build.sh` - this will invoke `lerna bootstrap` and `lerna run test`.
86-
All external dependencies will be installed and internal deps will be
87-
cross-linked.
77+
- __`scripts/buildup`__: builds the current module and all of it's dependencies (in topological order).
78+
- __`scripts/builddown`__: builds the current module and all of it's consumers (in topological order).
8879

89-
### buildup/builddown
80+
### Useful aliases
9081

91-
If you only want to work on a subset of the repo, you can use `scripts/buildup` and
92-
`scripts/builddown` to build a package and all it's dependencies (up) or
93-
dependents (down).
82+
You can also add a few useful aliases to your shell profile:
9483

95-
Make sure to run `./install.sh` from the root to make sure all modules are installed.
96-
97-
It is useful to add the `./scripts` directory to your PATH.
98-
99-
Then, change the working directory to any package in the repo and run:
84+
```bash
85+
# runs an npm script via lerna for a the current module
86+
alias lr='lerna run --stream --scope $(node -p "require(\"./package.json\").name")'
10087

101-
buildup # will also build all dependencies
88+
# runs "npm run build" (build + test) for the current module
89+
alias lb='lr build'
90+
alias lt='lr test'
10291

103-
Or:
92+
# runs "npm run watch" for the current module (recommended to run in a separate terminal session):
93+
alias lw='lr watch'
94+
```
10495

105-
builddown # will also build all consumers
96+
### pkglint
10697

107-
### Development Iteration
98+
The `pkglint` tool "lints" package.json files across the repo according
99+
to [rules.ts](tools/pkglint/lib/rules.ts).
108100

109-
After you've bootstrapped the repo, you would probably want to work on individual packages.
101+
To evaluate (and attempt to fix) all package linting issues in the repo, run the following command from the root
102+
of the repository (after boostrapping):
110103

111-
All packages in the repo have a two useful scripts: `prepare` and `watch`. In order to execute
112-
these scripts, use `lerna run --stream --scope <package> <script>`.
104+
```console
105+
$ lerna run pkglint
106+
```
113107

114-
> The reason you can't use "npm" is because dev tools are installed at the repository level
115-
> and they are needed in the PATH when executing most of the package scripts.
108+
You can also do that per package:
116109

117-
A useful shell alias would use the directory name as a scope:
110+
```console
111+
$ lr pkglint
112+
```
118113

119-
```bash
120-
# add to your ~/.zshrc or ~/.bashrc
121-
alias lr='lerna run --stream --scope $(node -p "require(\"./package.json\").name")'
114+
## Development Workflows
122115

123-
# more sugar
124-
alias lw='lr watch &'
125-
alias lp='lr prepare'
126-
```
116+
### Full clean build
127117

128-
Then, you could just go into any of the package directories and use "lr" to run scripts. For example:
118+
Clone the repo:
129119

130-
```bash
131-
cd packages/aws-cdk-s3
132-
lr watch
120+
```console
121+
$ git clone git@github.com/awslabs/aws-cdk
122+
$ cd aws-cdk
133123
```
134124

135-
### Linking against this repository
125+
If you already have a local repo and you want a fresh build, run `git clean -fdx` from the root.
136126

137-
The script `./link-all.sh` can be used to generate symlinks to all modules in
138-
this repository under some `node_module` directory. This can be used to develop
139-
against this repo as a local dependency.
140-
141-
One can use the `postinstall` script to symlink this repo:
127+
Install and build:
142128

143-
```json
144-
{
145-
"scripts": {
146-
"postinstall": "../aws-cdk/link-all.sh"
147-
}
148-
}
129+
```console
130+
$ ./install.sh
131+
$ ./build.sh
149132
```
150133

151-
This assumes this repo is a sibling of the target repo and will install the CDK
152-
as a linked dependency during __npm install__.
134+
If you also wish to package to all languages, make sure you have all the [toolchains](#Toolchains]
135+
and now run:
153136

137+
```
138+
$ ./pack.sh
139+
```
154140

155-
### Package Linter
141+
### Partial build
156142

157-
The `pkglint` tool normalizes all packages in the repo. It verifies package.json
158-
is normalized and adheres to the set of rules. To evaluate (and potentially fix)
159-
all package linting issues in the repo, run the following command from the root
160-
of the repository (after boostrapping):
143+
In many cases, you don't really need to build the entire project. Say you want to work
144+
on the `@aws-cdk/aws-ec2` module:
161145

162-
```bash
163-
npm run pkglint
146+
```console
147+
$ ./install.sh
148+
$ cd packages/@aws-cdk/aws-ec2
149+
$ ../../../scripts/buildup
164150
```
165151

166-
## jsii
152+
### Quick Iteration
167153

168-
The CDK uses [jsii](https://github.com/awslabs/jsii) to vend the framework to
169-
multiple programming languages. Since jsii is still not published to npm, we
170-
consume it as a bundled dependency.
154+
After you've built the modules you want to work on once, use `lr watch` for each module that
155+
you are modifying.
171156

172-
### Updating to a new version
157+
Watch the EC2 and IAM modules in a second terminal session:
173158

174-
Download an official jsii zip bundle and replace the file under `./vendor`.
175-
Any added dependencies, they will need to be added to the root `package.json`.
159+
```console
160+
$ cd packages/@aws-cdk/aws-ec2
161+
$ lr watch & # runs in the background
162+
$ cd packages/@aws-cdk/aws-iam
163+
$ lr watch & # runs in the background
164+
```
176165

177-
### Linking against a local jsii repository
166+
Code...
178167

179-
If you are making changes locally to jsii itself and wish to bind this repository to
180-
a local jsii repository, the best way we currently have is to use `npm link` to link
181-
various jsii modules from the other repository into the root of this repository.
168+
Now to test, you can either use `lr test` or invoke nodeunit directory (faster, since "test" will also build):
182169

183-
For example, if you wish to link against the `jsii` module:
170+
```console
171+
$ cd packages/@aws-cdk/aws-iam
172+
$ nodeunit test/test.*.js
173+
<BOOM>
174+
```
184175

185-
1. Go to `jsii/packages/jsii`
186-
2. Run `npm link .`
187-
3. Go to `aws-cdk/`
188-
4. Run `npm link jsii`.
176+
### Build Documentation Only
189177

190-
## Adding Language Support
178+
The CDK documentation source is hosted under [`./docs/src`](./docs/src).
179+
Module reference documentation is gathered after build from the `dist/sphinx` directory (generated by jsii from source via the `./pack.sh` script).
191180

192-
The CDK uses [jsii](https://github.com/awslabs/jsii) to generate language
193-
bindings for CDK classes, which proxy interaction to a node.js child process in
194-
runtime.
181+
To build the docs even if reference docs are not present:
195182

196-
To vend another language for the CDK (given there's jsii support for it):
197183

198-
1. Create a directory `packages/aws-cdk-xxx` (where "xxx" is the language).
199-
2. Look at [`aws-cdk-java/package.json`](packages/aws-cdk-java/package.json) as a reference
200-
on how to setup npm build that uses pacmak to generate the code for all CDK modules and
201-
then compile and wrap the package up.
202-
3. Edit [bundle-beta.sh](./bundle-beta.sh) and add CDK and jsii artifacts for
203-
your language under `repo/xxx`
204-
4. Add a **cdk init** template for your language (see
205-
[packages/aws-cdk/lib/init-templates](packages/aws-cdk/lib/init-templates)).
206-
5. Edit [getting-started.rst](packages/aws-cdk-docs/src/getting-started.rst) and
207-
make there there's a getting started sections and examples for the new
208-
language.
184+
```shell
185+
$ cd docs
186+
$ BUILD_DOCS_DEV=1 ./build-docs.sh
187+
```
209188

210189
## Dependencies
211190

@@ -260,16 +239,55 @@ We use `npm update` to
260239
5. Now, run `./build.sh` again to verify all tests pass.
261240
6. Submit a Pull Request.
262241

263-
## Documentation
242+
## Toolchains
264243

265-
The CDK documentation source is hosted under [`./docs/src`](./docs/src).
266-
Module reference documentation is gathered after build from the `dist/sphinx` directory (generated by jsii from source via the `./pack.sh` script).
244+
If you wish to use `pack.sh` to package the project to all supported languages, you will need the
245+
following toolchains installed:
267246

268-
To build the docs even if reference docs are not present:
247+
- [Node.js 8.11.0](https://nodejs.org/download/release/v8.11.0/)
248+
- [Java OpenJDK 8](http://openjdk.java.net/install/)
249+
- [.NET Core 2.0](https://www.microsoft.com/net/download)
250+
- [Python 3.6.5](https://www.python.org/downloads/release/python-365/)
251+
- [Ruby 2.5.1](https://www.ruby-lang.org/en/news/2018/03/28/ruby-2-5-1-released/)
269252

253+
## Linking against this repository
270254

271-
```shell
272-
$ cd docs
273-
$ BUILD_DOCS_DEV=1 ./build-docs.sh
255+
The script `./link-all.sh` can be used to generate symlinks to all modules in
256+
this repository under some `node_module` directory. This can be used to develop
257+
against this repo as a local dependency.
258+
259+
One can use the `postinstall` script to symlink this repo:
260+
261+
```json
262+
{
263+
"scripts": {
264+
"postinstall": "../aws-cdk/link-all.sh"
265+
}
266+
}
274267
```
275268

269+
This assumes this repo is a sibling of the target repo and will install the CDK
270+
as a linked dependency during __npm install__.
271+
272+
## Adding Language Support
273+
274+
The CDK uses [jsii](https://github.com/awslabs/jsii) to generate language
275+
bindings for CDK classes, which proxy interaction to a node.js child process in
276+
runtime.
277+
278+
To vend another language for the CDK (given there's jsii support for it):
279+
280+
1. Create a directory `packages/aws-cdk-xxx` (where "xxx" is the language).
281+
2. Look at [`aws-cdk-java/package.json`](packages/aws-cdk-java/package.json) as a reference
282+
on how to setup npm build that uses pacmak to generate the code for all CDK modules and
283+
then compile and wrap the package up.
284+
3. Edit [bundle-beta.sh](./bundle-beta.sh) and add CDK and jsii artifacts for
285+
your language under `repo/xxx`
286+
4. Add a **cdk init** template for your language (see
287+
[packages/aws-cdk/lib/init-templates](packages/aws-cdk/lib/init-templates)).
288+
5. Edit [getting-started.rst](packages/aws-cdk-docs/src/getting-started.rst) and
289+
make there there's a getting started sections and examples for the new
290+
language.
291+
292+
293+
[conventionalcommits]: https://www.conventionalcommits.org

0 commit comments

Comments
 (0)