Skip to content

Commit

Permalink
Centralize build logic, enforce code coverage (aws#337)
Browse files Browse the repository at this point in the history
BUILD

Reorganize build. This change introduces a new 'cdk-build-tools' package used
by all packages. All commands for all packages are now 'cdk-build', 'cdk-test',
etc. This centralizes the copy/pasted logic and provides a single point where
we can provide better Windows compatibility.

The 'cdk-build' script detects when sources are unchanged since the last
successful build and skips running the TypeScript compiler in that case,
which saves time if you only changed a couple of packages.

The 'cdk-integ' scripts are moved from @aws-cdk/assert to a new package
called cdk-integ-tools, otherwise the packages that the integ tools
depend could not be built using cdk-build-tools.

The build tools include a fingerpriting system where they'll calculate a
hash of a source tree and skip rebuilding if the hashes haven't changed.
An opportunistic rebuild is automatically triggered as part of
'cdk-test'.

COVERAGE

Code coverage is now checked for all packages using 'nyc'. The global config 
lives in the cdk-build-tools package.

Some packages have unit tests but don't have enough coverage. For those close
enough, add a couple tests to bump the coverage over the threshold.  For those
too far away, the thresholds are lowered per package. Those should be fixed as
soon as possible.

SECRETS

Add allowed git-secrets pattern for AWS account '123456789012', which is the
one account number allowed for use in tests.

ADDITIONAL FIXES

`pkglint` now properly checks the contents of the `test/` directory in
order to enforce the presence of the NPM testing commands.

Fixes aws#270
  • Loading branch information
rix0rrr authored Jul 17, 2018
1 parent 3ed832d commit 984953b
Show file tree
Hide file tree
Showing 225 changed files with 3,725 additions and 563 deletions.
2 changes: 2 additions & 0 deletions .gitallowed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The only AWS account number allowed to be used in tests (used by git-secrets)
123456789012
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ lerna-debug.log
dist
pack
.BUILD_COMPLETED
.local-npm
.local-npm
coverage
.nyc_output
.LAST_BUILD
9 changes: 6 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ rm -rf $BUILD_INDICATOR

export PATH=node_modules/.bin:$PATH

# Speed up build by reusing calculated tree hashes
# On dev machine, this speeds up the TypeScript part of the build by ~30%.
export MERKLE_BUILD_CACHE=$(mktemp -d)
trap "rm -rf $MERKLE_BUILD_CACHE" EXIT

echo "============================================================================================="
echo "building..."
lerna exec --stream "npm run build"
time lerna exec --stream "npm run build"

echo "============================================================================================="
echo "testing..."
lerna run --stream test

touch $BUILD_INDICATOR


15 changes: 11 additions & 4 deletions create-missing-libraries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ tslint.json
node_modules
dist
.jsii
.nyc_output
coverage
.LAST_BUILD
EOM

cat <<EOM > packages/${P}/.npmignore
Expand Down Expand Up @@ -63,13 +66,16 @@ EOM
"url": "git://github.com/awslabs/aws-cdk"
},
"scripts": {
"build": "cfn2ts --scope=${S} && jsii && tslint -p . && pkglint",
"watch": "jsii -w",
"lint": "jsii && tslint -p . --force",
"test": "nodeunit test/test.*.js && cdk-integ-assert",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"integ": "cdk-integ",
"pkglint": "pkglint -f"
},
"cdk-build": {
"cloudformation": "${S}"
},
"keywords": [
"aws",
"cdk",
Expand All @@ -83,6 +89,7 @@ EOM
"license": "LicenseRef-LICENSE",
"devDependencies": {
"@aws-cdk/assert": "^${VERSION}",
"cdk-build-tools": "^${VERSION}",
"cfn2ts": "^${VERSION}",
"pkglint": "^${VERSION}"
},
Expand Down
1 change: 1 addition & 0 deletions examples/cdk-examples-typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.LAST_BUILD
11 changes: 6 additions & 5 deletions examples/cdk-examples-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "A bunch of CDK examples",
"private": true,
"scripts": {
"build": "tsc && tslint -p . && pkglint",
"watch": "tsc -w",
"lint": "tsc && tslint -p . --force",
"test": "echo ok",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"cdk": "cdk",
"pkglint": "pkglint -f"
},
Expand All @@ -18,7 +18,8 @@
"license": "LicenseRef-LICENSE",
"devDependencies": {
"aws-cdk": "^0.7.3-beta",
"pkglint": "^0.7.3-beta"
"pkglint": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/cloudformation": "^0.7.3-beta",
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/apigateway/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ node_modules
*.generated.ts
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
14 changes: 9 additions & 5 deletions packages/@aws-cdk/apigateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
"url": "git://github.com/awslabs/aws-cdk"
},
"scripts": {
"build": "cfn2ts --scope=AWS::ApiGateway && jsii && tslint -p . && pkglint",
"watch": "jsii -w",
"lint": "jsii && tslint -p . --force",
"test": "nodeunit test/test.*.js && cdk-integ-assert",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"integ": "cdk-integ",
"pkglint": "pkglint -f"
},
"cdk-build": {
"cloudformation": "AWS::ApiGateway"
},
"keywords": [
"aws",
"cdk",
Expand All @@ -37,7 +40,8 @@
"devDependencies": {
"@aws-cdk/assert": "^0.7.3-beta",
"cfn2ts": "^0.7.3-beta",
"pkglint": "^0.7.3-beta"
"pkglint": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/core": "^0.7.3-beta"
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/applet-js/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
*.d.ts
node_modules
dist

.LAST_BUILD
.nyc_output
coverage
11 changes: 6 additions & 5 deletions packages/@aws-cdk/applet-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"cdk-applet-js": "bin/cdk-applet-js"
},
"scripts": {
"build": "tslint -p . && tsc && chmod +x bin/cdk-applet-js && pkglint",
"watch": "tsc -w",
"lint": "tsc && tslint -p . --force",
"test": "/bin/bash test/test-applet.sh",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"pkglint": "pkglint -f"
},
"author": {
Expand All @@ -21,7 +21,8 @@
"license": "LicenseRef-LICENSE",
"devDependencies": {
"@types/yamljs": "^0.2.0",
"pkglint": "^0.7.3-beta"
"pkglint": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/core": "^0.7.3-beta",
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/applicationautoscaling/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ node_modules
*.generated.ts
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
14 changes: 9 additions & 5 deletions packages/@aws-cdk/applicationautoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
"url": "git://github.com/awslabs/aws-cdk"
},
"scripts": {
"build": "cfn2ts --scope=AWS::ApplicationAutoScaling && jsii && tslint -p . && pkglint",
"watch": "jsii -w",
"lint": "jsii && tslint -p . --force",
"test": "nodeunit test/test.*.js && cdk-integ-assert",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"integ": "cdk-integ",
"pkglint": "pkglint -f"
},
"cdk-build": {
"cloudformation": "AWS::ApplicationAutoScaling"
},
"keywords": [
"aws",
"cdk",
Expand All @@ -37,7 +40,8 @@
"devDependencies": {
"@aws-cdk/assert": "^0.7.3-beta",
"cfn2ts": "^0.7.3-beta",
"pkglint": "^0.7.3-beta"
"pkglint": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/core": "^0.7.3-beta"
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/appsync/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ node_modules
*.generated.ts
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
14 changes: 9 additions & 5 deletions packages/@aws-cdk/appsync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
"url": "git://github.com/awslabs/aws-cdk"
},
"scripts": {
"build": "cfn2ts --scope=AWS::AppSync && jsii && tslint -p . && pkglint",
"watch": "jsii -w",
"lint": "jsii && tslint -p . --force",
"test": "nodeunit test/test.*.js && cdk-integ-assert",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"integ": "cdk-integ",
"pkglint": "pkglint -f"
},
"cdk-build": {
"cloudformation": "AWS::AppSync"
},
"keywords": [
"aws",
"cdk",
Expand All @@ -37,7 +40,8 @@
"devDependencies": {
"@aws-cdk/assert": "^0.7.3-beta",
"cfn2ts": "^0.7.3-beta",
"pkglint": "^0.7.3-beta"
"pkglint": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/core": "^0.7.3-beta"
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/assert/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
*.d.ts
node_modules
dist

.LAST_BUILD
.nyc_output
coverage
20 changes: 10 additions & 10 deletions packages/@aws-cdk/assert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tslint -p . && tsc && chmod +x bin/cdk-integ bin/cdk-integ-assert && pkglint",
"watch": "tsc -w",
"lint": "tslint -p . --force",
"test": "nodeunit test/test.*.js",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"pkglint": "pkglint -f"
},
"bin": {
"cdk-integ": "bin/cdk-integ",
"cdk-integ-assert": "bin/cdk-integ-assert"
"nyc": {
"lines": 40,
"branches": 30
},
"author": {
"name": "Amazon Web Services",
"url": "https://aws.amazon.com"
},
"license": "LicenseRef-LICENSE",
"devDependencies": {
"pkglint": "^0.7.3-beta"
"pkglint": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/cx-api": "^0.7.3-beta",
"@aws-cdk/cloudformation-diff": "^0.7.3-beta",
"@aws-cdk/core": "^0.7.3-beta",
"@aws-cdk/cx-api": "^0.7.3-beta",
"aws-cdk": "^0.7.3-beta",
"source-map-support": "^0.5.6"
},
"repository": {
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/athena/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ node_modules
*.generated.ts
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
12 changes: 8 additions & 4 deletions packages/@aws-cdk/athena/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
"dotnet": "Aws.Cdk.Athena"
}
},
"cdk-build": {
"cloudformation": "AWS::Athena"
},
"repository": {
"type": "git",
"url": "git://github.com/awslabs/aws-cdk"
},
"scripts": {
"build": "cfn2ts --scope=AWS::Athena && jsii && tslint -p . && pkglint",
"watch": "jsii -w",
"lint": "jsii && tslint -p . --force",
"test": "nodeunit test/test.*.js && cdk-integ-assert",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"integ": "cdk-integ",
"pkglint": "pkglint -f"
},
Expand All @@ -36,6 +39,7 @@
"license": "LicenseRef-LICENSE",
"devDependencies": {
"@aws-cdk/assert": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta",
"cfn2ts": "^0.7.3-beta",
"pkglint": "^0.7.3-beta"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/autoscaling/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ tslint.json
node_modules
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
14 changes: 9 additions & 5 deletions packages/@aws-cdk/autoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
"url": "git://github.com/awslabs/aws-cdk"
},
"scripts": {
"build": "cfn2ts --scope=AWS::AutoScaling && jsii && tslint -p . && pkglint",
"watch": "jsii -w",
"lint": "jsii && tslint -p . --force",
"test": "nodeunit test/test.*.js && cdk-integ-assert",
"build": "cdk-build",
"watch": "cdk-watch",
"lint": "cdk-lint",
"test": "cdk-test",
"integ": "cdk-integ",
"pkglint": "pkglint -f"
},
"cdk-build": {
"cloudformation": "AWS::AutoScaling"
},
"keywords": [
"aws",
"cdk",
Expand All @@ -37,7 +40,8 @@
"devDependencies": {
"@aws-cdk/assert": "^0.7.3-beta",
"cfn2ts": "^0.7.3-beta",
"pkglint": "^0.7.3-beta"
"pkglint": "^0.7.3-beta",
"cdk-build-tools": "^0.7.3-beta"
},
"dependencies": {
"@aws-cdk/core": "^0.7.3-beta"
Expand Down
4 changes: 4 additions & 0 deletions packages/@aws-cdk/autoscalingplans/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ node_modules
*.generated.ts
dist
.jsii

.LAST_BUILD
.nyc_output
coverage
Loading

0 comments on commit 984953b

Please sign in to comment.