Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: revert "chore: compat checks fail if a release has happened" #19070

Merged
merged 1 commit into from Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 16 additions & 13 deletions scripts/check-api-compatibility.sh
Expand Up @@ -14,7 +14,7 @@ package_name() {
# Doesn't use 'npm view' as that is slow. Direct curl'ing npmjs is better
package_exists_on_npm() {
pkg=$1
ver=${2:-} # optional
ver=$2 # optional
curl -I 2>/dev/null https://registry.npmjs.org/$pkg/$ver | head -n 1 | grep 200 >/dev/null
}

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

#----------------------------------------------------------------------

# dirs_for_existing_pkgs DIRECTORY VERSION
#
# Input a directory and a version, output the directory IF it exists on NPM at that version
# Input a directory, output the directory IF it exists on NPM
dirs_for_existing_pkgs() {
local dir="$1"
local ver="$2"
if package_exists_on_npm $(package_name $dir) $ver; then
if package_exists_on_npm $(package_name $dir); then
echo "$dir"
echo -n "." >&2
else
Expand All @@ -52,24 +49,30 @@ export -f dirs_for_existing_pkgs

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

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

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

rm -rf $tmpdir
mkdir -p $tmpdir

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

#----------------------------------------------------------------------
Expand Down