Skip to content

Commit 9c83ee5

Browse files
authored
chore: compat checks fail if a release has happened (#19017)
If a PR is branched off of a version that introduces a new package, and lives longer than the release, the "does package exist?" check is wrong, and fails the PR build. This is usually fixed by another "Update from master", but that's an annoying step that sometimes takes a while. - Let's say the branch was forked at 1.142.0 - The branch adds a new package - That package is released as its initial version as 1.143.0 - When the PR next builds (still at 1.142.0), it will do the following checks: - Does the package exist at all? (Answer: yes) - If so, try to install it at 1.142.0, because that's what we're diffing against (This explodes, because the package does not exist at that version). Instead of doing a versionless "does the package exist at all" check, always check the existence of the actual version we'll be diffing against. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 64d26cc commit 9c83ee5

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

scripts/check-api-compatibility.sh

+13-16
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package_name() {
1414
# Doesn't use 'npm view' as that is slow. Direct curl'ing npmjs is better
1515
package_exists_on_npm() {
1616
pkg=$1
17-
ver=$2 # optional
17+
ver=${2:-} # optional
1818
curl -I 2>/dev/null https://registry.npmjs.org/$pkg/$ver | head -n 1 | grep 200 >/dev/null
1919
}
2020

@@ -32,10 +32,13 @@ jsii_package_dirs=$(list_jsii_packages)
3232

3333
#----------------------------------------------------------------------
3434

35-
# Input a directory, output the directory IF it exists on NPM
35+
# dirs_for_existing_pkgs DIRECTORY VERSION
36+
#
37+
# Input a directory and a version, output the directory IF it exists on NPM at that version
3638
dirs_for_existing_pkgs() {
3739
local dir="$1"
38-
if package_exists_on_npm $(package_name $dir); then
40+
local ver="$2"
41+
if package_exists_on_npm $(package_name $dir) $ver; then
3942
echo "$dir"
4043
echo -n "." >&2
4144
else
@@ -49,30 +52,24 @@ export -f dirs_for_existing_pkgs
4952

5053
if ! ${SKIP_DOWNLOAD:-false}; then
5154
echo "Filtering on existing packages on NPM..." >&2
52-
# In parallel
53-
existing_pkg_dirs=$(echo "$jsii_package_dirs" | xargs -n1 -P4 -I {} bash -c 'dirs_for_existing_pkgs "$@"' _ {})
54-
existing_names=$(echo "$existing_pkg_dirs" | xargs -n1 -P4 -I {} bash -c 'package_name "$@"' _ {})
55-
echo " Done." >&2
5655

5756
echo "Determining baseline version..." >&2
5857
version=$(node -p 'require("./scripts/resolve-version.js").version')
5958
echo " Current version is $version." >&2
59+
echo "Using version '$version' as the baseline..."
6060

61-
if ! package_exists_on_npm aws-cdk $version; then
62-
major_version=$(echo "$version" | sed -e 's/\..*//g')
63-
echo " Version $version does not exist in npm. Falling back to package major version ${major_version}" >&2
64-
existing_names=$(echo "$existing_names" | sed -e "s/$/@$major_version/")
65-
else
66-
echo "Using version '$version' as the baseline..."
67-
existing_names=$(echo "$existing_names" | sed -e "s/$/@$version/")
68-
fi
61+
# Filter packages by existing at the target version
62+
existing_pkg_dirs=$(echo "$jsii_package_dirs" | xargs -n1 -P4 -I {} bash -c 'dirs_for_existing_pkgs "$@" "'$version'"' _ {})
63+
existing_names=$(echo "$existing_pkg_dirs" | xargs -n1 -P4 -I {} bash -c 'package_name "$@"' _ {})
64+
install_versions=$(for name in $existing_names; do echo "${name}@${version}"; done)
65+
echo " Done." >&2
6966

7067
rm -rf $tmpdir
7168
mkdir -p $tmpdir
7269

7370
echo "Installing from NPM..." >&2
7471
# use npm7 to automatically install peer dependencies
75-
(cd $tmpdir && npx npm@^7.0.0 install --prefix $tmpdir $existing_names)
72+
(cd $tmpdir && npx npm@^7.0.0 install --prefix $tmpdir $install_versions)
7673
fi
7774

7875
#----------------------------------------------------------------------

0 commit comments

Comments
 (0)