forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-api-compatibility.sh
executable file
·76 lines (63 loc) · 1.95 KB
/
check-api-compatibility.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Check API compatibility of all packages
set -eu
repo_root="$(cd $(dirname $0)/.. && pwd)"
tmpdir=/tmp/compat-check
package_name() {
node -pe "require('$1/package.json').name"
}
#----------------------------------------------------------------------
echo "Listing packages..." >&2
package_dirs=()
package_names=()
for dir in $(npx lerna ls -p); do
if [[ -f $dir/.jsii ]]; then
package_dirs+=("$dir")
package_names+=("$(package_name $dir)")
fi
done
#----------------------------------------------------------------------
if ! ${SKIP_DOWNLOAD:-false}; then
echo "Filtering on existing packages on NPM..." >&2
for i in ${!package_dirs[@]}; do
echo -n "${package_names[$i]}... "
if npm view --loglevel silent ${package_names[$i]} > /dev/null; then
echo "Exists."
else
echo "NEW."
unset 'package_names[i]'
unset 'package_dirs[i]'
fi
done
rm -rf $tmpdir
mkdir -p $tmpdir
echo "Installing from NPM..." >&2
(cd $tmpdir && npm install --prefix $tmpdir ${package_names[@]})
fi
#----------------------------------------------------------------------
# get the current version from Lerna
current_version=$(npx lerna ls -pl | head -n 1 | cut -d ':' -f 3)
echo "Checking compatibility..." >&2
success=true
for i in ${!package_dirs[*]}; do
if [[ ! -d $tmpdir/node_modules/${package_names[$i]} ]]; then continue; fi
echo -n "${package_names[$i]}... "
if npx jsii-diff \
--keys \
--ignore-file ${repo_root}/allowed-breaking-changes.txt \
$tmpdir/node_modules/${package_names[$i]} \
${package_dirs[$i]} \
2>$tmpdir/output.txt; then
echo "OK."
else
success=false
echo "CHANGES."
cat $tmpdir/output.txt
fi
done
if $success; then
echo "All OK." >&2
else
echo "Some packages seem to have undergone breaking API changes. Please avoid." >&2
exit 1
fi