Skip to content

Commit

Permalink
chore: revert "chore: compat checks fail if a release has happened" (#…
Browse files Browse the repository at this point in the history
…19070)

Reverts #19017. This PR is breaking our CI Pipeline.
  • Loading branch information
kaizencc committed Feb 21, 2022
1 parent 11d6c69 commit 3dc32dc
Showing 1 changed file with 16 additions and 13 deletions.
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

0 comments on commit 3dc32dc

Please sign in to comment.