set -e
REPO_ROOT=$(git rev-parse --show-toplevel)
cd "$REPO_ROOT"
remote="$1"
url="$2"
echo "=== Pre-push validation ==="
echo "Pushing to: $remote ($url)"
echo ""
echo "[1/5] Manifest portability..."
python3 - <<'PY'
try:
import tomllib
except ModuleNotFoundError:
import tomli as tomllib
with open("Cargo.toml", "rb") as fh:
data = tomllib.load(fh)
bad = [
(section, name, spec["path"])
for section in ("dependencies", "dev-dependencies", "build-dependencies")
for name, spec in data.get(section, {}).items()
if isinstance(spec, dict) and "path" in spec
]
if bad:
raise SystemExit(
"Manifest portability check failed:\n"
+ "\n".join(
f" - {section}.{name} uses unexpected local path dependency {path}"
for section, name, path in bad
)
)
print("Manifest portability: ok (root dependencies use registry versions)")
PY
echo ""
echo "[2/5] Format check..."
cargo fmt --all --check || {
echo "Formatting issues. Run: cargo fmt --all"
exit 1
}
echo ""
echo "[3/5] Clippy..."
cargo clippy --locked -p aicx --all-targets -- -D warnings
cargo clippy --locked -p aicx-embeddings --features gguf -- -D warnings
cargo clippy --locked -p aicx --features native-embedder --all-targets -- -D warnings
echo ""
echo "[4/5] Tests..."
cargo test --locked -p aicx --all-targets
cargo test --locked -p aicx-embeddings --features gguf
cargo test --locked -p aicx --features native-embedder --test native_embedder
echo ""
echo "[5/5] Semgrep (optional)..."
if command -v semgrep >/dev/null 2>&1; then
semgrep --config auto --error --quiet . --exclude target || {
echo "Semgrep found issues. Fix before pushing."
exit 1
}
elif command -v pipx >/dev/null 2>&1; then
pipx run semgrep --config auto --error --quiet . --exclude target || {
echo "Semgrep found issues. Fix before pushing."
exit 1
}
else
echo "Semgrep not available; skipping."
fi
echo ""
echo "=== All pre-push checks passed ==="