From ae90cba34179ed890ddea07685c86e8be6e52e96 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Tue, 9 Jun 2020 05:44:05 +0100 Subject: [PATCH] chore: re-enable using current pkg versions for api compat checks (#8427) This was originally added in commit https://github.com/aws/aws-cdk/commit/3dd21b9b212f96720519ac12f9cb538c697e9343. However, the script fails during a bump build when the package version in lerna.json is ahead of the latest published in NPM. This was worked around by turning this feature off - https://github.com/aws/aws-cdk/commit/09a1f33f975e49f92bfa708e3d3d03984863a28d. Re-enable this feature and handle version in lerna.json may be ahead of NPM. ### Testing Manually tested three cases - * When version in `lerna.json` is <= package published in NPM * When version in `lerna.json` is > package published in NPM * When `DOWNLOAD_LATEST` is set to `true`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- build.sh | 2 +- scripts/check-api-compatibility.sh | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 44c020454216a..b58fa80e1c563 100755 --- a/build.sh +++ b/build.sh @@ -60,6 +60,6 @@ echo "========================================================================== echo "building..." time lerna run $bail --stream $runtarget || fail -DOWNLOAD_LATEST=true /bin/bash scripts/check-api-compatibility.sh +/bin/bash scripts/check-api-compatibility.sh touch $BUILD_INDICATOR diff --git a/scripts/check-api-compatibility.sh b/scripts/check-api-compatibility.sh index a63ccb5f7fa9b..ca15553418f72 100755 --- a/scripts/check-api-compatibility.sh +++ b/scripts/check-api-compatibility.sh @@ -13,7 +13,9 @@ package_name() { # # Doesn't use 'npm view' as that is slow. Direct curl'ing npmjs is better package_exists_on_npm() { - curl -I 2>/dev/null https://registry.npmjs.org/$1 | head -n 1 | grep 200 >/dev/null + pkg=$1 + ver=$2 # optional + curl -I 2>/dev/null https://registry.npmjs.org/$pkg/$ver | head -n 1 | grep 200 >/dev/null } @@ -53,10 +55,13 @@ if ! ${SKIP_DOWNLOAD:-false}; then existing_names=$(echo "$jsii_package_dirs" | xargs -n1 -P4 -I {} bash -c 'dirs_to_existing_names "$@"' _ {}) echo " Done." >&2 - if ! ${DOWNLOAD_LATEST:-false}; then - current_version=$(node -p 'require("./lerna.json").version') + current_version=$(node -p 'require("./lerna.json").version') + echo "Current version in lerna.json is $current_version" + if ! ${DOWNLOAD_LATEST:-false} && package_exists_on_npm aws-cdk $current_version; then echo "Using package version ${current_version} as baseline" existing_names=$(echo "$existing_names" | sed -e "s/$/@$current_version/") + else + echo "However, using the latest version from NPM as the baseline" fi rm -rf $tmpdir