56 lines
1.5 KiB
Bash
Executable File
56 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
cd "$ROOT_DIR"
|
|
|
|
BASE_REF="${1:-}"
|
|
HEAD_REF="${2:-HEAD}"
|
|
|
|
if [[ -z "$BASE_REF" ]]; then
|
|
BASE_REF="${GITHUB_BASE_REF:-}"
|
|
if [[ -n "$BASE_REF" ]]; then
|
|
BASE_REF="origin/$BASE_REF"
|
|
elif git rev-parse --verify origin/master >/dev/null 2>&1; then
|
|
BASE_REF="origin/master"
|
|
elif git rev-parse --verify origin/main >/dev/null 2>&1; then
|
|
BASE_REF="origin/main"
|
|
else
|
|
BASE_REF="HEAD~1"
|
|
fi
|
|
fi
|
|
|
|
CHANGED="$(git diff --name-only "$BASE_REF"..."$HEAD_REF" || true)"
|
|
if [[ -z "$CHANGED" ]]; then
|
|
echo "[contract-check] no changes detected"
|
|
exit 0
|
|
fi
|
|
|
|
API_CHANGED=0
|
|
DOC_CHANGED=0
|
|
TS_CHANGED=0
|
|
|
|
if printf '%s\n' "$CHANGED" | grep -E -q '^(backend/app/api/|backend/app/schemas/|backend/app/services/signal_planner_service.py|backend/app/services/model_routing_service.py)'; then
|
|
API_CHANGED=1
|
|
fi
|
|
|
|
if printf '%s\n' "$CHANGED" | grep -E -q '^(frontend/src/api/|frontend/src/types/|frontend/src/pages/ModelRoutingConfigPage.tsx)'; then
|
|
TS_CHANGED=1
|
|
fi
|
|
|
|
if printf '%s\n' "$CHANGED" | grep -E -q '^docs/architecture/(MASTER_CONTRACT.md|API_CONTRACTS.md|DATAFLOW.md)$'; then
|
|
DOC_CHANGED=1
|
|
fi
|
|
|
|
if [[ "$API_CHANGED" -eq 1 && "$TS_CHANGED" -eq 0 ]]; then
|
|
echo "[contract-check] backend contract changed but frontend TS contract not updated"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ "$API_CHANGED" -eq 1 && "$DOC_CHANGED" -eq 0 ]]; then
|
|
echo "[contract-check] backend contract changed but architecture docs not updated"
|
|
exit 1
|
|
fi
|
|
|
|
echo "[contract-check] pass"
|