Skip to content

Commit cbe6a53

Browse files
authored
check for api breakage and prepare to test with thread sanitizer in ci (#122)
motivation: better ci testing changes: * add api breakage script to test api breakage in ci * add "shell" utility docker-compose task to run api breakage script * change test task to treat warning as errors * prepare to test with thread sanitizer in 5.1
1 parent 4eedb14 commit cbe6a53

5 files changed

+153
-3
lines changed

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ENV LANGUAGE en_US.UTF-8
1313

1414
# dependencies
1515
RUN apt-get update && apt-get install -y wget
16-
RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools libz-dev # used by integration tests
16+
RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools libz-dev curl jq # used by integration tests
1717

1818
# ruby and jazzy for docs generation
1919
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev

docker/docker-compose.1804.50.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ services:
1111

1212
test:
1313
image: async-http-client:18.04-5.0
14+
15+
shell:
16+
image: async-http-client:18.04-5.0

docker/docker-compose.1804.51.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ services:
1111

1212
test:
1313
image: async-http-client:18.04-5.1
14+
environment: []
15+
#- SANITIZER_ARG=--sanitize=thread
16+
17+
shell:
18+
image: async-http-client:18.04-5.1

docker/docker-compose.yaml

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ services:
2121

2222
sanity:
2323
<<: *common
24-
command: /bin/bash -cl "./scripts/sanity.sh"
24+
command: /bin/bash -xcl "./scripts/sanity.sh"
2525

2626
test:
2727
<<: *common
28-
command: /bin/bash -cl "swift test"
28+
command: /bin/bash -xcl "swift test -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"
29+
30+
# util
31+
32+
shell:
33+
<<: *common
34+
entrypoint: /bin/bash
2935

3036
docs:
3137
<<: *common

scripts/check_no_api_breakages.sh

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the AsyncHTTPClient open source project
5+
##
6+
## Copyright (c) 2018-2019 Swift Server Working Group and the AsyncHTTPClient project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of AsyncHTTPClient project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
##===----------------------------------------------------------------------===##
17+
##
18+
## This source file is part of the SwiftNIO open source project
19+
##
20+
## Copyright (c) 2017-2018 Apple Inc. and the SwiftNIO project authors
21+
## Licensed under Apache License v2.0
22+
##
23+
## See LICENSE.txt for license information
24+
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
25+
##
26+
## SPDX-License-Identifier: Apache-2.0
27+
##
28+
##===----------------------------------------------------------------------===##
29+
30+
set -eu
31+
32+
# repodir
33+
function all_modules() {
34+
local repodir="$1"
35+
(
36+
set -eu
37+
cd "$repodir"
38+
swift package dump-package | jq '.products |
39+
map(select(.type | has("library") )) |
40+
map(.name) | .[]' | tr -d '"'
41+
)
42+
}
43+
44+
# repodir tag output
45+
function build_and_do() {
46+
local repodir=$1
47+
local tag=$2
48+
local output=$3
49+
50+
(
51+
cd "$repodir"
52+
git checkout -q "$tag"
53+
swift build
54+
while read -r module; do
55+
swift api-digester -sdk "$sdk" -dump-sdk -module "$module" \
56+
-o "$output/$module.json" -I "$repodir/.build/debug"
57+
done < <(all_modules "$repodir")
58+
)
59+
}
60+
61+
function usage() {
62+
echo >&2 "Usage: $0 REPO-GITHUB-URL NEW-VERSION OLD-VERSIONS..."
63+
echo >&2
64+
echo >&2 "This script requires a Swift 5.1+ toolchain."
65+
echo >&2
66+
echo >&2 "Examples:"
67+
echo >&2
68+
echo >&2 "Check between master and tag 2.1.1 of swift-nio:"
69+
echo >&2 " $0 https://github.com/apple/swift-nio master 2.1.1"
70+
echo >&2
71+
echo >&2 "Check between HEAD and commit 64cf63d7 using the provided toolchain:"
72+
echo >&2 " xcrun --toolchain org.swift.5120190702a $0 ../some-local-repo HEAD 64cf63d7"
73+
}
74+
75+
if [[ $# -lt 3 ]]; then
76+
usage
77+
exit 1
78+
fi
79+
80+
sdk=/
81+
if [[ "$(uname -s)" == Darwin ]]; then
82+
sdk=$(xcrun --show-sdk-path)
83+
fi
84+
85+
hash jq 2> /dev/null || { echo >&2 "ERROR: jq must be installed"; exit 1; }
86+
tmpdir=$(mktemp -d /tmp/.check-api_XXXXXX)
87+
repo_url=$1
88+
new_tag=$2
89+
shift 2
90+
91+
repodir="$tmpdir/repo"
92+
git clone "$repo_url" "$repodir"
93+
git -C "$repodir" fetch -q origin '+refs/pull/*:refs/remotes/origin/pr/*'
94+
errors=0
95+
96+
for old_tag in "$@"; do
97+
mkdir "$tmpdir/api-old"
98+
mkdir "$tmpdir/api-new"
99+
100+
echo "Checking public API breakages from $old_tag to $new_tag"
101+
102+
build_and_do "$repodir" "$new_tag" "$tmpdir/api-new/"
103+
build_and_do "$repodir" "$old_tag" "$tmpdir/api-old/"
104+
105+
for f in "$tmpdir/api-new"/*; do
106+
f=$(basename "$f")
107+
report="$tmpdir/$f.report"
108+
if [[ ! -f "$tmpdir/api-old/$f" ]]; then
109+
echo "NOTICE: NEW MODULE $f"
110+
continue
111+
fi
112+
113+
echo -n "Checking $f... "
114+
swift api-digester -sdk "$sdk" -diagnose-sdk \
115+
--input-paths "$tmpdir/api-old/$f" -input-paths "$tmpdir/api-new/$f" 2>&1 \
116+
> "$report" 2>&1
117+
118+
if ! shasum "$report" | grep -q cefc4ee5bb7bcdb7cb5a7747efa178dab3c794d5; then
119+
echo ERROR
120+
echo >&2 "=============================="
121+
echo >&2 "ERROR: public API change in $f"
122+
echo >&2 "=============================="
123+
cat >&2 "$report"
124+
errors=$(( errors + 1 ))
125+
else
126+
echo OK
127+
fi
128+
done
129+
rm -rf "$tmpdir/api-new" "$tmpdir/api-old"
130+
done
131+
132+
if [[ "$errors" == 0 ]]; then
133+
echo "OK, all seems good"
134+
fi
135+
echo done
136+
exit "$errors"

0 commit comments

Comments
 (0)