Skip to content

Commit 12e4668

Browse files
Add check-for-breaking-api-changes.sh script (#21)
### Motivation We want to know when we are making breaking changes to our public API. ### Modifications Add a script that wraps `swift package diagnose-api-breaking-changes` which we'll start to use in CI. ### Result A script can be used to validate the current repo state against a baseline repo and treeish for breaking API changes. ### Notes Running this script produces the following output: ```console ❯ BASELINE_REPO_URL=https://github.com/apple/swift-openapi-runtime BASELINE_TREEISH=main bash scripts/check-for-breaking-api-changes.sh ** Checking required environment variables... ** Fetching baseline: https://github.com/apple/swift-openapi-runtime#main... From https://github.com/apple/swift-openapi-runtime * branch main -> FETCH_HEAD ** Checking for API changes since https://github.com/apple/swift-openapi-runtime#main (e81f70f)... Building for debugging... Build complete! (7.53s) No breaking changes detected in OpenAPIRuntime ** ✅ No breaking API changes detected. ``` Then making the following local change... ```diff diff --git a/Sources/OpenAPIRuntime/Conversion/Converter.swift b/Sources/OpenAPIRuntime/Conversion/Converter.swift index 2aac666..f2abb63 100644 --- a/Sources/OpenAPIRuntime/Conversion/Converter.swift +++ b/Sources/OpenAPIRuntime/Conversion/Converter.swift @@ -35,7 +35,8 @@ public struct Converter: Sendable { /// Creates a new converter with the behavior specified by the configuration. public init( - configuration: Configuration + configuration: Configuration, + i: Int = 1 ) { self.configuration = configuration ``` ...and rerunning the script, gives the following output... ``` ... 1 breaking change detected in OpenAPIRuntime: 💔 API breakage: constructor Converter.init(configuration:) has been removed ** ERROR: ❌ Breaking API changes detected. ``` --------- Signed-off-by: Si Beaumont <[email protected]>
1 parent e81f70f commit 12e4668

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

Comments
 (0)