-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-api-breakage.sh
More file actions
executable file
·51 lines (40 loc) · 1.36 KB
/
check-api-breakage.sh
File metadata and controls
executable file
·51 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
# API Breaking Changes Check
#
# This script checks whether the current Swift package introduces
# API-breaking changes compared to a baseline.
#
# Baseline selection logic:
# - In GitHub Actions PRs: uses the PR base branch
# - Otherwise: uses the latest git tag
#
# If no tags exist at all, the check is skipped with a warning.
set -euo pipefail
# Logging helpers
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() {
error "$@"
exit 1
}
# Determine baseline reference
if [ -n "${GITHUB_BASE_REF:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_SERVER_URL:-}" ]; then
log "Running in PR context — using base branch: ${GITHUB_BASE_REF}"
git fetch "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \
"${GITHUB_BASE_REF}:pull-base-ref"
BASELINE_REF="pull-base-ref"
else
log "No PR context detected — checking for existing tags"
git fetch --tags
if ! git tag | grep -q .; then
log "⚠️ No git tags found — skipping API breakage check"
exit 0
fi
BASELINE_REF=$(git describe --tags --abbrev=0)
fi
log "Using baseline: ${BASELINE_REF}"
# Run SwiftPM API breakage diagnosis
#
# This command exits non-zero if API-breaking changes are detected.
swift package diagnose-api-breaking-changes "$BASELINE_REF"
log "✅ No API-breaking changes detected."