diff --git a/packages/@aws-cdk/aws-codestar/.npmignore b/packages/@aws-cdk/aws-codestar/.npmignore index 687587358d66a..f826a6bca989a 100644 --- a/packages/@aws-cdk/aws-codestar/.npmignore +++ b/packages/@aws-cdk/aws-codestar/.npmignore @@ -16,4 +16,7 @@ dist .LAST_PACKAGE .jsii -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-lakeformation/.npmignore b/packages/@aws-cdk/aws-lakeformation/.npmignore index 687587358d66a..f826a6bca989a 100644 --- a/packages/@aws-cdk/aws-lakeformation/.npmignore +++ b/packages/@aws-cdk/aws-lakeformation/.npmignore @@ -16,4 +16,7 @@ dist .LAST_PACKAGE .jsii -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-managedblockchain/.npmignore b/packages/@aws-cdk/aws-managedblockchain/.npmignore index 687587358d66a..f826a6bca989a 100644 --- a/packages/@aws-cdk/aws-managedblockchain/.npmignore +++ b/packages/@aws-cdk/aws-managedblockchain/.npmignore @@ -16,4 +16,7 @@ dist .LAST_PACKAGE .jsii -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/aws-qldb/.npmignore b/packages/@aws-cdk/aws-qldb/.npmignore index 687587358d66a..f826a6bca989a 100644 --- a/packages/@aws-cdk/aws-qldb/.npmignore +++ b/packages/@aws-cdk/aws-qldb/.npmignore @@ -16,4 +16,7 @@ dist .LAST_PACKAGE .jsii -*.tsbuildinfo \ No newline at end of file +*.tsbuildinfo + +# Include .jsii +!.jsii diff --git a/packages/@aws-cdk/cloudformation-diff/lib/format.ts b/packages/@aws-cdk/cloudformation-diff/lib/format.ts index 740418b9c711e..7f5291d6b52ed 100644 --- a/packages/@aws-cdk/cloudformation-diff/lib/format.ts +++ b/packages/@aws-cdk/cloudformation-diff/lib/format.ts @@ -66,7 +66,7 @@ function formatSecurityChangesWithBanner(formatter: Formatter, templateDiff: Tem formatter.formatIamChanges(templateDiff.iamChanges); formatter.formatSecurityGroupChanges(templateDiff.securityGroupChanges); - formatter.warning(`(NOTE: There may be security-related changes not in this list. See http://bit.ly/cdk-2EhF7Np)`); + formatter.warning(`(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)`); formatter.printSectionFooter(); } diff --git a/packages/aws-cdk/.npmignore b/packages/aws-cdk/.npmignore index 5a821b0934717..84c89bed768b9 100644 --- a/packages/aws-cdk/.npmignore +++ b/packages/aws-cdk/.npmignore @@ -12,5 +12,6 @@ dist *.snk !lib/init-templates/*/*/tsconfig.json +!test/integ/cli/**/*.js *.tsbuildinfo diff --git a/packages/aws-cdk/package.json b/packages/aws-cdk/package.json index 7487c20a657e9..f5d4d19e0ec5a 100644 --- a/packages/aws-cdk/package.json +++ b/packages/aws-cdk/package.json @@ -16,8 +16,8 @@ "package": "cdk-package", "build+test+package": "npm run build+test && npm run package", "build+test": "npm run build && npm test", - "integ-cli": "CDK_REPO=$PWD/../.. test/integ/cli/test.sh", - "integ-init": "CDK_DIST=$PWD/../../dist test/integ/init/test-all.sh" + "integ-cli": "test/integ/run-against-repo test/integ/cli/test.sh", + "integ-init": "test/integ/run-against-dist test/integ/init/test-all.sh" }, "cdk-build": { "pre": [ diff --git a/packages/aws-cdk/test/integ/cli/README.md b/packages/aws-cdk/test/integ/cli/README.md new file mode 100644 index 0000000000000..f22e59447b380 --- /dev/null +++ b/packages/aws-cdk/test/integ/cli/README.md @@ -0,0 +1,25 @@ +# CDK CLI Integration Tests + +These tests require AWS credentials, and exercise various aspects of the +CLI on a simple JavaScript CDK app (stored in `app/`). + +## Entry point + +``` +./test.sh +``` + +## Configuration + +AWS credentials must be configured. + +Optional configuration: + +* `AWS_DEFAULT_REGION`, what region to deploy the stacks in. +* `STACK_NAME_PREFIX`, used to run multiple instances of these tests in the + same account side-by-side without them stepping on each other. Using + a unique name on every run is risky since the account may overflow with + stacks if cleanup happens to fail. Defaults based on the value of `IS_CANARY` + if not supplied. +* `IS_CANARY`, true or false. Affects the default stack name prefix to make + integration test and canary runs unique. diff --git a/packages/aws-cdk/test/integ/cli/common.bash b/packages/aws-cdk/test/integ/cli/common.bash index d9603d88a5ec8..95ee98f14ddf9 100644 --- a/packages/aws-cdk/test/integ/cli/common.bash +++ b/packages/aws-cdk/test/integ/cli/common.bash @@ -1,24 +1,6 @@ set -eu scriptdir=$(cd $(dirname $0) && pwd) -source $scriptdir/../common/util.bash - -CDK_REPO="${CDK_REPO:-}" - -# If CDK_REPO is set to point to the root of the CDK source repository -# the CLI and modules will be taken from there. Otherwise, we will honor -# the usual IS_CANARY flag for integration test-vs-canary mode switch. -if [ -z "${CDK_REPO}" -a -z "${TESTS_PREPARED:-}" ]; then - prepare_toolkit - preload_npm_packages - - # Only do this once - export TESTS_PREPARED=1 -fi - -if [[ "${CDK_REPO}" != "" ]]; then - export CDK_REPO=$(cd $CDK_REPO && pwd) - alias cdk=$CDK_REPO/packages/aws-cdk/bin/cdk -fi +cd ${scriptdir} if [[ -z "${CREDS_SET:-}" ]]; then # Check that credentials are configured @@ -26,14 +8,29 @@ if [[ -z "${CREDS_SET:-}" ]]; then export CREDS_SET=1 fi -cd ${scriptdir} -if ${IS_CANARY:-false}; then - export STACK_NAME_PREFIX=cdk-toolkit-canary -else - export STACK_NAME_PREFIX=cdk-toolkit-integration +if [[ "${STACK_NAME_PREFIX:-}" == "" ]]; then + if ${IS_CANARY:-false}; then + export STACK_NAME_PREFIX=cdk-toolkit-canary + else + export STACK_NAME_PREFIX=cdk-toolkit-integration + fi fi +#---------------------------------------------------------------------------------- +# Only functions from here on out + +function log() { + echo >&2 "| $@" +} + +function header() { + log + log "============================================================================================" + log $@ + log "============================================================================================" +} + function cleanup_stack() { local stack_arn=$1 echo "| ensuring ${stack_arn} is cleaned up" @@ -42,50 +39,47 @@ function cleanup_stack() { fi } +integ_test_dir=/tmp/cdk-integ-test + +# Prepare the app fixture +# +# If this is done in the main test script, it will be skipped +# in the subprocess scripts since the app fixture can just be reused. +function prepare_fixture() { + if [[ -z "${FIXTURE_PREPARED:-}" ]]; then + log "Preparing app fixture..." + + rm -rf $integ_test_dir + mkdir -p $integ_test_dir + cp -R app/* $integ_test_dir + cd $integ_test_dir + + npm install \ + @aws-cdk/core \ + @aws-cdk/aws-sns \ + @aws-cdk/aws-iam \ + @aws-cdk/aws-lambda \ + @aws-cdk/aws-ssm \ + @aws-cdk/aws-ecr-assets \ + @aws-cdk/aws-ec2 + + echo "| setup complete at: $PWD" + echo "| 'cdk' is: $(type -p cdk)" + + export FIXTURE_PREPARED=1 + fi +} + function cleanup() { cleanup_stack ${STACK_NAME_PREFIX}-test-1 cleanup_stack ${STACK_NAME_PREFIX}-test-2 cleanup_stack ${STACK_NAME_PREFIX}-iam-test } -function install_dep() { - local dep=$1 - - if [ -n "${CDK_REPO}" ]; then - mkdir -p node_modules/@aws-cdk - local source="${CDK_REPO}/packages/${dep}" - local target="$PWD/node_modules/${dep}" - echo "| symlinking dependency ${target} => ${source}" - ln -s ${source} ${target} - else - echo "| installing dependency ${dep}" - npm i --no-save ${dep} - fi -} - function setup() { cleanup - rm -rf /tmp/cdk-integ-test - mkdir -p /tmp/cdk-integ-test - cp -R app/* /tmp/cdk-integ-test - cd /tmp/cdk-integ-test - - if [ -n "${CDK_REPO}" ]; then - local cdk_bin="${CDK_REPO}/packages/aws-cdk/bin" - echo "| adding ${cdk_bin} to PATH" - export PATH=${cdk_bin}:$PATH - fi - - install_dep @aws-cdk/core - install_dep @aws-cdk/aws-sns - install_dep @aws-cdk/aws-iam - install_dep @aws-cdk/aws-lambda - install_dep @aws-cdk/aws-ssm - install_dep @aws-cdk/aws-ecr-assets - install_dep @aws-cdk/aws-ec2 - - echo "| setup complete at: $PWD" - echo "| 'cdk' is: $(which cdk)" + prepare_fixture + cd $integ_test_dir } function fail() { diff --git a/packages/aws-cdk/test/integ/cli/test-cdk-context.sh b/packages/aws-cdk/test/integ/cli/test-cdk-context.sh index 86781c56a4d2d..4670bf409ff10 100755 --- a/packages/aws-cdk/test/integ/cli/test-cdk-context.sh +++ b/packages/aws-cdk/test/integ/cli/test-cdk-context.sh @@ -4,10 +4,6 @@ scriptdir=$(cd $(dirname $0) && pwd) source ${scriptdir}/common.bash # ---------------------------------------------------------- -rm -rf /tmp/cdk-integ-test -mkdir -p /tmp/cdk-integ-test -cd /tmp/cdk-integ-test - cat > cdk.context.json <&1 | grep "this is the context value" > /dev/null && { echo "Shoul # Test that forced delete of the context key does not error cdk context -f --reset contextkey +rm -f cdk.context.json + echo "✅ success" diff --git a/packages/aws-cdk/test/integ/cli/test-cdk-ssm-parameter-provider-error.sh b/packages/aws-cdk/test/integ/cli/test-cdk-ssm-parameter-provider-error.sh index b6e3f47f23be3..3b007f6e37b93 100755 --- a/packages/aws-cdk/test/integ/cli/test-cdk-ssm-parameter-provider-error.sh +++ b/packages/aws-cdk/test/integ/cli/test-cdk-ssm-parameter-provider-error.sh @@ -15,7 +15,8 @@ function cdk_synth() { } assert "cdk_synth ${STACK_NAME_PREFIX}-missing-ssm-parameter -c test:ssm-parameter-name=${parameterName}" <&2 "| $@" -} - -function header() { - log - log "============================================================================================" - log $@ - log "============================================================================================" -} - -# This is where build artifacts reside -dist=$(cd ${CDK_DIST:-$PWD} && pwd) - -# NPM Workspace. Will have CDK CLI and verdaccio installed into it. -npmws=$(mktemp -d) -export PATH=${npmws}/node_modules/.bin:$PATH - -function update_verdaccio_config() { - local verdaccio_config="$1" - local proxy="${2:-}" - - cat > "${verdaccio_config}" <&2 ${verdaccio_config} -} - -function config_npm_verdaccio() { - log >&2 "configuring npm to use verdaccio" - - export npm_config_userconfig="${dist}/.npmrc" - echo "registry=http://localhost:4873/" > ${npm_config_userconfig} - echo "//localhost:4873/:_authToken=none" >> ${npm_config_userconfig} - echo "" >> ${npm_config_userconfig} -} - -function run_verdaccio_with_packages() { - if [ -n "${VERDACCIO_RUNNING:-}" ]; then - log >&2 "verdaccio is already running" - config_npm_verdaccio - return - fi - - #------------------------------------------------------------------------------ - # Start a local npm repository and install the CDK from the distribution to it - #------------------------------------------------------------------------------ - header "Starting local NPM Repository" - local verdaccio_config="${npmws}/config.yaml" - - if ! which verdaccio; then - cd $npmws - npm install --no-save verdaccio - cd - - fi - - update_verdaccio_config "${verdaccio_config}" - verdaccio --config "${verdaccio_config}" & - local publisher_pid=$! - trap "echo 'shutting down verdaccio publisher'; kill ${publisher_pid} || true" EXIT - log >&2 "waiting for publisher verdaccio to start..." - sleep 1 - log "publisher verdaccio pid: ${publisher_pid}" - - config_npm_verdaccio - - for tgz in "$@"; do - log "publishing $tgz" - npm publish $tgz - done - - kill ${publisher_pid} - wait ${publisher_pid} || true - - # start consumer verdaccio with npm - header "Starting verdaccio for consumption (with npm uplink)" - update_verdaccio_config "${verdaccio_config}" "proxy: npmjs" - verdaccio --config "${verdaccio_config}" & - local consumer_pid=$! - trap "echo 'shutting down verdaccio consumer'; kill ${consumer_pid} || true" EXIT - log >&2 "waiting for consumer verdaccio to start..." - sleep 1 - log "consumer verdaccio pid: ${consumer_pid}" - - export VERDACCIO_RUNNING=1 -} - -# Install CDK CLI, make sure it's on the PATH -function prepare_toolkit() { - cd $npmws - if ${IS_CANARY:-false}; then - # Latest version of toolkit - npm install aws-cdk - else - # Toolkit version that is in the dist directory - npm install $(ls $dist/js/aws-cdk-*.tgz | grep -E 'aws-cdk-[0-9.]+.tgz') - verify_installed_cli_version - fi - cd - -} - -# Make sure that installed CLI matches the build version -# -# Only works in integ mode. -function verify_installed_cli_version() { - local expected_version="$(node -e "console.log(require('${dist}/build.json').version)")" - header "Expected CDK version: ${expected_version}" - - # Execute "cdk --version" as a validation that the toolkit is installed - local actual_version="$(cdk --version | cut -d" " -f1)" - - if [ "${expected_version}" != "${actual_version}" ]; then - log "Mismatched CDK version. Expected: ${expected_version}, actual: ${actual_version}" - cdk --version - exit 1 - else - log "Verified CDK version is: ${expected_version}" - fi -} - -# In integration test mode, make it so that the local NPM packages are installed -# when 'npm install @aws-cdk/xxx' is run. -# -# In canary mode, do nothing. -function preload_npm_packages() { - if ${IS_CANARY:-false}; then - return - fi - - if [ ! -d "$dist/js" ]; then - echo "$dist/js not found - expected to have npm build artifacts" - exit 1 - fi - - run_verdaccio_with_packages $dist/js/*.tgz -} - -function prepare_java_packages() { - if ${IS_CANARY:-false}; then - return - fi - - # copy the maven staging repo to the maven local repo and set as M2 home - # this ensures that the canary builds against the build artifacts, not maven central - if [ ! -d $dist/java ]; then - echo "JSII build artifacts missing when running in integration mode" >&2 - exit 1 - fi - - export MAVEN_CONFIG=${MAVEN_CONFIG:-$HOME/.m2} - rsync -av $dist/java/ ${MAVEN_CONFIG}/repository -} - -function prepare_nuget_packages() { - real_dotnet=$(which dotnet) - - if ${IS_CANARY:-false}; then - return - fi - - # JSII build artifacts should be used during integration tests - # This directory does not exist in canary mode (IS_CANARY=true) - nuget_source=$dist/dotnet - - if [ ! -d "$nuget_source" ]; then - echo "JSII build artifacts missing when running in integration mode" >&2 - exit 1 - fi -} - -# Hijack the 'dotnet' command to include local sources in integ mode -function dotnet() { - if [[ "${1:-}" == "build" ]]; then - shift - if ${IS_CANARY:-false}; then - $real_dotnet build \ - --source https://api.nuget.org/v3/index.json \ - "$@" - else - $real_dotnet build \ - --source $nuget_source \ - --source https://api.nuget.org/v3/index.json \ - "$@" - fi - else - $real_dotnet "$@" - fi -} - -# pip_install REQUIREMENTS_FILE -function pip_install_r() { - if ${IS_CANARY:-false}; then - pip install -r $1 - return - fi - - pip install $dist/python/*.whl -} diff --git a/packages/aws-cdk/test/integ/init/common.bash b/packages/aws-cdk/test/integ/init/common.bash new file mode 100644 index 0000000000000..4bb3ce4eff837 --- /dev/null +++ b/packages/aws-cdk/test/integ/init/common.bash @@ -0,0 +1,19 @@ +set -eu +init_test_dir=/tmp/cdk-init-test + +function setup() { + rm -rf $init_test_dir + mkdir -p $init_test_dir + cd $init_test_dir +} + +function log() { + echo >&2 "| $@" +} + +function header() { + log + log "============================================================================================" + log $@ + log "============================================================================================" +} diff --git a/packages/aws-cdk/test/integ/init/test-all.sh b/packages/aws-cdk/test/integ/init/test-all.sh index 808184ec96460..f3bafe07cf908 100755 --- a/packages/aws-cdk/test/integ/init/test-all.sh +++ b/packages/aws-cdk/test/integ/init/test-all.sh @@ -6,3 +6,5 @@ $scriptdir/test-java.sh $scriptdir/test-javascript.sh $scriptdir/test-python.sh $scriptdir/test-typescript.sh + +echo "SUCCESS" diff --git a/packages/aws-cdk/test/integ/init/test-csharp.sh b/packages/aws-cdk/test/integ/init/test-csharp.sh index 7e0a44ead493f..381259fb6750f 100755 --- a/packages/aws-cdk/test/integ/init/test-csharp.sh +++ b/packages/aws-cdk/test/integ/init/test-csharp.sh @@ -4,16 +4,15 @@ #------------------------------------------------------------------ set -e scriptdir=$(cd $(dirname $0) && pwd) -source ${scriptdir}/../common/util.bash +source ${scriptdir}/common.bash header C# -prepare_toolkit -prepare_nuget_packages #------------------------------------------------------------------ # Run the test -appdir=$(mktemp -d) -cd ${appdir} +setup cdk init -l csharp -t app -dotnet build src -cdk synth hello-cdk-1 +dotnet build \ + --source https://api.nuget.org/v3/index.json \ + src +cdk synth diff --git a/packages/aws-cdk/test/integ/init/test-java.sh b/packages/aws-cdk/test/integ/init/test-java.sh index 9082ffd4c2ba7..612a4a9627f7e 100755 --- a/packages/aws-cdk/test/integ/init/test-java.sh +++ b/packages/aws-cdk/test/integ/init/test-java.sh @@ -4,15 +4,12 @@ #------------------------------------------------------------------ set -e scriptdir=$(cd $(dirname $0) && pwd) -source ${scriptdir}/../common/util.bash +source ${scriptdir}/common.bash header Java -prepare_toolkit -prepare_java_packages #------------------------------------------------------------------ # Run the test -appdir=$(mktemp -d) -cd ${appdir} +setup cdk init -l java -t app mvn package diff --git a/packages/aws-cdk/test/integ/init/test-javascript.sh b/packages/aws-cdk/test/integ/init/test-javascript.sh index f1ed4079c9961..c5d4e69d45fb3 100755 --- a/packages/aws-cdk/test/integ/init/test-javascript.sh +++ b/packages/aws-cdk/test/integ/init/test-javascript.sh @@ -4,16 +4,13 @@ #------------------------------------------------------------------ set -e scriptdir=$(cd $(dirname $0) && pwd) -source ${scriptdir}/../common/util.bash - -prepare_toolkit -preload_npm_packages +source ${scriptdir}/common.bash #------------------------------------------------------------------ for template in app sample-app; do echo "Trying template $template" - cd $(mktemp -d) + setup cdk init -l javascript -t $template npm ls # this will fail if we have unmet peer dependencies cdk synth diff --git a/packages/aws-cdk/test/integ/init/test-python.sh b/packages/aws-cdk/test/integ/init/test-python.sh index 117a850baf016..d33c6ad193551 100755 --- a/packages/aws-cdk/test/integ/init/test-python.sh +++ b/packages/aws-cdk/test/integ/init/test-python.sh @@ -2,22 +2,20 @@ #------------------------------------------------------------------ # setup #------------------------------------------------------------------ -set -e +set -eu scriptdir=$(cd $(dirname $0) && pwd) -source ${scriptdir}/../common/util.bash +source ${scriptdir}/common.bash header Python -prepare_toolkit #------------------------------------------------------------------ for template in app sample-app; do echo "Trying template $template" - # Provide a template otherwise mktemp might generate a name like - # 'tmp.AFCVIQ' which the Python init template REALLY doesn't like. - cd $(mktemp -d /tmp/pythonXXXXXXX) + setup cdk init -l python $template source .env/bin/activate - pip_install_r requirements.txt + type -p pip + pip install -r requirements.txt cdk synth done diff --git a/packages/aws-cdk/test/integ/init/test-typescript.sh b/packages/aws-cdk/test/integ/init/test-typescript.sh index 60adabee326f3..0efcbb445cff3 100755 --- a/packages/aws-cdk/test/integ/init/test-typescript.sh +++ b/packages/aws-cdk/test/integ/init/test-typescript.sh @@ -4,17 +4,17 @@ #------------------------------------------------------------------ set -e scriptdir=$(cd $(dirname $0) && pwd) -source ${scriptdir}/../common/util.bash +source ${scriptdir}/common.bash header TypeScript -prepare_toolkit -preload_npm_packages #------------------------------------------------------------------ for template in app sample-app lib; do echo "Trying template $template" - cd $(mktemp -d) + + setup + cdk init -l typescript -t $template npm ls # this will fail if we have unmet peer dependencies npm run build diff --git a/packages/aws-cdk/test/integ/run-against-dist b/packages/aws-cdk/test/integ/run-against-dist new file mode 100755 index 0000000000000..e152f2a173090 --- /dev/null +++ b/packages/aws-cdk/test/integ/run-against-dist @@ -0,0 +1,44 @@ +#!/bin/bash +# Run a given test against the packages found in the CDK distribution. +# +# - Set up verdaccio and publish all NPM tarballs found in the given directory to it. +# - Install the CLI from that Verdaccio fixture somewhere and put it +# on the PATH. +# - Prepare the various package managers to take their packages from dist/ as well. +# +# Parameter: DIST_ROOT, if different than the current directory. +set -eu +scriptdir=$(cd $(dirname $0) && pwd) +source $scriptdir/run-against-dist.bash + +# If DIST_ROOT is not given, guess at a sane location. +if [[ "${DIST_ROOT:-}" == "" && -f $scriptdir/../../../dist/build.json ]]; then + DIST_ROOT=$scriptdir/../../../dist +fi + +dist_root=$(cd ${DIST_ROOT:-.} && pwd) + +if [[ ! -f $dist_root/build.json ]]; then + echo "$dist_root does not seem to be a built CDK distribution (change directory or use DIST_ROOT)" >&2 + exit 1 +fi + +#serve_npm_packages + +# Install the CLI and put it on the path +(cd $npmws && npm install aws-cdk) +export PATH=$npmws/node_modules/.bin:$PATH + +#verify_installed_cli_version +prepare_java_packages +prepare_nuget_packages +prepare_python_packages + +# Install additional tool wrappers before running the target script +export PATH="$scriptdir/run-wrappers/dist:$PATH" +hash -r + +# Run target script +# NOTE: no 'exec' because we need to shutdown verdaccio only AFTER we've +# run the subscript. +"$@" diff --git a/packages/aws-cdk/test/integ/run-against-dist.bash b/packages/aws-cdk/test/integ/run-against-dist.bash new file mode 100644 index 0000000000000..c648495b077ff --- /dev/null +++ b/packages/aws-cdk/test/integ/run-against-dist.bash @@ -0,0 +1,192 @@ +# Helper functions to go with 'run-against-dist' +# NPM Workspace. Will have CDK CLI and verdaccio installed into it. +npmws=/tmp/cdk-rundist +rm -rf $npmws +mkdir -p $npmws + +function log() { + echo >&2 "| $@" +} + +function header() { + log + log "============================================================================================" + log $@ + log "============================================================================================" +} + +function serve_npm_packages() { + if [ -n "${VERDACCIO_PID:-}" ]; then + log >&2 "verdaccio is already running" + use_verdaccio + return + fi + + tarballs=$dist_root/js/*.tgz + + log "Discovering local package names..." + # Read the package names from each tarball, so that we can generate + # a Verdaccio config that will keep each of these packages locally + # and not go to NPMJS for it. + package_names="" + for tgz in $tarballs; do + name=$(node -pe 'JSON.parse(process.argv[1]).name' "$(tar xOzf $tgz package/package.json)") + package_names="$package_names $name" + done + + #------------------------------------------------------------------------------ + # Start a local npm repository and install the CDK from the distribution to it + #------------------------------------------------------------------------------ + header "Starting local NPM Repository" + local verdaccio_config="${npmws}/config.yaml" + + verdacciobin=$(type -p verdaccio) || { + (cd $npmws && npm install --no-save verdaccio) + verdacciobin=$npmws/node_modules/.bin/verdaccio + } + + # start consumer verdaccio with npm + header "Starting verdaccio (with npm uplink)" + write_verdaccio_config "${verdaccio_config}" "$package_names" + $verdacciobin --config "${verdaccio_config}" & + local pid=$! + trap "echo 'shutting down verdaccio'; kill ${pid} || true" EXIT + log >&2 "waiting for verdaccio to start..." + sleep 1 + log "consumer verdaccio pid: ${pid}" + + export VERDACCIO_PID=$pid + + use_verdaccio + + log "Publishing NPM tarballs..." + for tgz in $tarballs; do + # Doesn't matter what directory it is, just shouldn't be the + # aws-cdk package directory. + (cd $npmws && npm --quiet publish $tgz) + done +} + +function write_verdaccio_config() { + local verdaccio_config="$1" + local packages="${2:-}" + + cat > "${verdaccio_config}" <> "${verdaccio_config}" <> "${verdaccio_config}" <&2 ${verdaccio_config} +} + +function use_verdaccio() { + log >&2 "configuring npm to use verdaccio" + + # Token MUST be passed via .npmrc: https://github.com/npm/npm/issues/15565 + export npm_config_userconfig="${npmws}/.npmrc" + echo "//localhost:4873/:_authToken=none" >> ${npm_config_userconfig} + echo "" >> ${npm_config_userconfig} + + # Pass registry via environment variable, so that if this script gets run via 'npm run' + # and all $npm_config_xxx settings are passed via environment variables, we still + # get to override it (the file would normally be ignored in that case). + export npm_config_registry=http://localhost:4873/ +} + + +# Make sure that installed CLI matches the build version +function verify_installed_cli_version() { + local expected_version="$(node -e "console.log(require('${dist_root}/build.json').version)")" + header "Expected CDK version: ${expected_version}" + + log "Found CDK: $(type -p cdk)" + + # Execute "cdk --version" as a validation that the toolkit is installed + local actual_version="$(cdk --version | cut -d" " -f1)" + + if [ "${expected_version}" != "${actual_version}" ]; then + log "Mismatched CDK version. Expected: ${expected_version}, actual: ${actual_version}" + cdk --version + exit 1 + else + log "Verified CDK version is: ${expected_version}" + fi +} + +function prepare_java_packages() { + log "Preparing Maven packages..." + + # copy the maven staging repo to the maven local repo and set as M2 home + # this ensures that the canary builds against the build artifacts, not maven central + if [ ! -d $dist_root/java ]; then + echo "Maven packages missing at $dist_root/java" >&2 + exit 1 + fi + + export MAVEN_CONFIG=${MAVEN_CONFIG:-$HOME/.m2} + rsync -a $dist_root/java/ ${MAVEN_CONFIG}/repository +} + +function prepare_nuget_packages() { + # For NuGet, we wrap the "dotnet" CLI command to use local packages. + log "Hijacking 'dotnet build' command..." + + ORIGINAL_DOTNET=$(type -p dotnet) || { echo "No 'dotnet' found" >&2; exit 1; } + export ORIGINAL_DOTNET + export NUGET_SOURCE=$dist_root/dotnet + + if [ ! -d "$NUGET_SOURCE" ]; then + echo "NuGet packages missing at $NUGET_SOURCE" >&2 + exit 1 + fi +} + +# pip_install REQUIREMENTS_FILE +function prepare_python_packages() { + log "Hijacking 'pip install' command..." + + # We can't use a $PATH hijack, because we'll be creating a venv + # later which will re-hijack ours with a 'pip' binary. Use a function instead, + # the real logic will reside in "pip_" + + ORIGINAL_PIP=$(type -p pip) || { echo "No 'pip' found" >&2; exit 1; } + export ORIGINAL_PIP + export PYTHON_WHEELS=$dist_root/python + + if [ ! -d "$PYTHON_WHEELS" ]; then + echo "Python build artifacts missing at $PYTHON_WHEELS" >&2 + exit 1 + fi + + export -f pip +} + +function pip() { + exec pip_ "$@" +} diff --git a/packages/aws-cdk/test/integ/run-against-release b/packages/aws-cdk/test/integ/run-against-release new file mode 100755 index 0000000000000..5ea9bf34ff7d4 --- /dev/null +++ b/packages/aws-cdk/test/integ/run-against-release @@ -0,0 +1,19 @@ +#!/bin/bash +# Run a given test against the publicly released packages +# +# - Install the latest CLI somewhere and put it on the PATH. +# - Run the script +set -eu +scriptdir=$(cd $(dirname $0) && pwd) + +# NPM Workspace. Will have CDK CLI installed into it. +npmws=/tmp/cdk-runrelease +rm -rf $npmws +mkdir -p $npmws + +# Install the CLI and put it on the PATH +(cd $npmws && npm install aws-cdk) +export PATH=$npmws/node_modules/.bin:$PATH + +# Run the inner script +exec "$@" diff --git a/packages/aws-cdk/test/integ/run-against-repo b/packages/aws-cdk/test/integ/run-against-repo new file mode 100755 index 0000000000000..601097c880d18 --- /dev/null +++ b/packages/aws-cdk/test/integ/run-against-repo @@ -0,0 +1,21 @@ +#!/bin/bash +# Script to run a given test against the monorepo. +# +# Set up paths so that `cdk` binary is on the path, and make it +# so that `npm install` symlinks from the monorepo package directories. +set -eu + +cli_dir=$(cd $(dirname $0)/../.. && pwd) +repo_root=$(cd $cli_dir/../.. && pwd) + +if [[ ! -f $repo_root/package.json ]]; then + echo "$repo_root does not seem to be the root of the aws-cdk repository." >&2 + exit 1 +fi + +export REPO_ROOT="$repo_root" +export ORIGINAL_NPM="$(type -p npm)" + +export PATH="$cli_dir/bin:$cli_dir/test/integ/run-wrappers/repo:$PATH" +hash -r +exec "$@" diff --git a/packages/aws-cdk/test/integ/run-wrappers/repo/dotnet b/packages/aws-cdk/test/integ/run-wrappers/repo/dotnet new file mode 100755 index 0000000000000..7ab610a0e7afd --- /dev/null +++ b/packages/aws-cdk/test/integ/run-wrappers/repo/dotnet @@ -0,0 +1,3 @@ +#!/bin/bash +echo "$0: cannot build this kind of project against the repo. Only pure NPM projects are supported. Use 'run-against-dist' instead." >&2 +exit 1 diff --git a/packages/aws-cdk/test/integ/run-wrappers/repo/mvn b/packages/aws-cdk/test/integ/run-wrappers/repo/mvn new file mode 100755 index 0000000000000..7ab610a0e7afd --- /dev/null +++ b/packages/aws-cdk/test/integ/run-wrappers/repo/mvn @@ -0,0 +1,3 @@ +#!/bin/bash +echo "$0: cannot build this kind of project against the repo. Only pure NPM projects are supported. Use 'run-against-dist' instead." >&2 +exit 1 diff --git a/packages/aws-cdk/test/integ/run-wrappers/repo/npm b/packages/aws-cdk/test/integ/run-wrappers/repo/npm new file mode 100755 index 0000000000000..204398e857c71 --- /dev/null +++ b/packages/aws-cdk/test/integ/run-wrappers/repo/npm @@ -0,0 +1,25 @@ +#!/bin/bash +# Wrapper for 'npm' which will symlink packages from the monorepo. +set -eu +command=$1 + +lerna=$REPO_ROOT/node_modules/.bin/lerna + +if [[ "$command" == "install" || "$command" == "i" ]]; then + npmargs="install" + shift + + while [[ "${1:-}" != "" ]]; do + packageloc=$(cd $REPO_ROOT && npx lerna ls --loglevel silent -p --scope $1) && { + # Rewrite to 'npm install /path/to/@aws-cdk/pkg' + npmargs="$npmargs $packageloc" + } || { + npmargs="$npmargs $1" + } + shift + done + + exec $ORIGINAL_NPM $npmargs +fi + +exec $ORIGINAL_NPM "$@" diff --git a/packages/aws-cdk/test/integ/run-wrappers/repo/pip_ b/packages/aws-cdk/test/integ/run-wrappers/repo/pip_ new file mode 100755 index 0000000000000..9553f9cefe2d9 --- /dev/null +++ b/packages/aws-cdk/test/integ/run-wrappers/repo/pip_ @@ -0,0 +1,4 @@ +#!/bin/bash +echo "$0: cannot build this kind of project against the repo. Only pure NPM projects are supported. Use 'run-against-dist' instead." >&2 +exit 1 +