|
| 1 | +#!/usr/bin/env bash |
| 2 | +##===----------------------------------------------------------------------===## |
| 3 | +## |
| 4 | +## This source file is part of the SwiftOpenAPIGenerator open source project |
| 5 | +## |
| 6 | +## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator 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 SwiftOpenAPIGenerator project authors |
| 11 | +## |
| 12 | +## SPDX-License-Identifier: Apache-2.0 |
| 13 | +## |
| 14 | +##===----------------------------------------------------------------------===## |
| 15 | + |
| 16 | +set -euo pipefail |
| 17 | + |
| 18 | +log() { printf -- "** %s\n" "$*" >&2; } |
| 19 | +error() { printf -- "** ERROR: %s\n" "$*" >&2; } |
| 20 | +fatal() { error "$@"; exit 1; } |
| 21 | + |
| 22 | +CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 23 | +REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" |
| 24 | + |
| 25 | +log "Checking required environment variables..." |
| 26 | +test -n "${BASELINE_REPO_URL:-}" || fatal "BASELINE_REPO_URL unset" |
| 27 | +test -n "${BASELINE_TREEISH:-}" || fatal "BASELINE_TREEISH unset" |
| 28 | + |
| 29 | +log "Fetching baseline: ${BASELINE_REPO_URL}#${BASELINE_TREEISH}..." |
| 30 | +git -C "${REPO_ROOT}" fetch "${BASELINE_REPO_URL}" "${BASELINE_TREEISH}" |
| 31 | +BASELINE_COMMIT=$(git -C "${REPO_ROOT}" rev-parse FETCH_HEAD) |
| 32 | + |
| 33 | +log "Checking for API changes since ${BASELINE_REPO_URL}#${BASELINE_TREEISH} (${BASELINE_COMMIT})..." |
| 34 | +swift package --package-path "${REPO_ROOT}" diagnose-api-breaking-changes \ |
| 35 | + "${BASELINE_COMMIT}" \ |
| 36 | + && RC=$? || RC=$? |
| 37 | + |
| 38 | +if [ "${RC}" -ne 0 ]; then |
| 39 | + fatal "❌ Breaking API changes detected." |
| 40 | + exit "${RC}" |
| 41 | +fi |
| 42 | +log "✅ No breaking API changes detected." |
0 commit comments