diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3c004e2..ca2db624 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: runs-on: macos-13 name: Test Library steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Select Xcode 15.0.1 run: sudo xcode-select -s /Applications/Xcode_15.0.1.app - name: Run tests @@ -28,9 +28,21 @@ jobs: runs-on: macos-13 name: Build Examples steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Select Xcode 15.0.1 run: sudo xcode-select -s /Applications/Xcode_15.0.1.app - name: Build examples run: make build-examples + + check-breaking-changes: + runs-on: macos-13 + name: Check for Breaking API Changes + steps: + - uses: actions/checkout@v4 + - name: Select Xcode 15.0.1 + run: sudo xcode-select -s /Applications/Xcode_15.0.1.app + - run: | + BASELINE_TREEISH=${{ github.base_ref }} \ + BASELINE_REPO_URL=${{ github.server_url }}/${{ github.repository }} \ + ./scripts/check-for-breaking-api-changes.sh diff --git a/scripts/check-for-breaking-api-changes.sh b/scripts/check-for-breaking-api-changes.sh new file mode 100644 index 00000000..d2ce9812 --- /dev/null +++ b/scripts/check-for-breaking-api-changes.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftOpenAPIGenerator open source project +## +## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +set -euo pipefail + +log() { printf -- "** %s\n" "$*" >&2; } +error() { printf -- "** ERROR: %s\n" "$*" >&2; } +fatal() { error "$@"; exit 1; } + +CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)" + +log "Checking required environment variables..." +test -n "${BASELINE_REPO_URL:-}" || fatal "BASELINE_REPO_URL unset" +test -n "${BASELINE_TREEISH:-}" || fatal "BASELINE_TREEISH unset" + +log "Fetching baseline: ${BASELINE_REPO_URL}#${BASELINE_TREEISH}..." +git -C "${REPO_ROOT}" fetch "${BASELINE_REPO_URL}" "${BASELINE_TREEISH}" +BASELINE_COMMIT=$(git -C "${REPO_ROOT}" rev-parse FETCH_HEAD) + +log "Checking for API changes since ${BASELINE_REPO_URL}#${BASELINE_TREEISH} (${BASELINE_COMMIT})..." +swift package --package-path "${REPO_ROOT}" diagnose-api-breaking-changes \ + "${BASELINE_COMMIT}" \ + && RC=$? || RC=$? + +if [ "${RC}" -ne 0 ]; then + fatal "❌ Breaking API changes detected." + exit "${RC}" +fi +log "✅ No breaking API changes detected."