|
| 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