set -e
echo "Running pre-push checks..."
if [ ! -f "Cargo.toml" ]; then
echo "ERROR: Cargo.toml not found. This script should be run from the project root."
exit 1
fi
echo "Checking version synchronization..."
CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
NPM_VERSION=$(grep '"version":' package.json | head -1 | sed 's/.*"version": "\(.*\)".*/\1/')
if [ "$CARGO_VERSION" != "$NPM_VERSION" ]; then
echo "ERROR: Version mismatch detected!"
echo " Cargo.toml version: $CARGO_VERSION"
echo " package.json version: $NPM_VERSION"
echo " Please ensure both files have the same version."
exit 1
fi
echo "Running clippy (linter)..."
cargo clippy --lib --all-features -- -D warnings -D clippy::uninlined_format_args
cargo clippy --bins --all-features -- -D warnings
echo "Checking code formatting..."
cargo fmt --check
echo "Running tests..."
export DIRECTORY_INDEXER_DATA_DIR=/tmp/directory-indexer-test
export DIRECTORY_INDEXER_QDRANT_COLLECTION=directory-indexer-test
cargo test --lib
cargo test tests
echo "Checking for security vulnerabilities..."
if command -v cargo-audit >/dev/null 2>&1; then
cargo audit
else
echo "Installing cargo-audit..."
cargo install cargo-audit
cargo audit
fi
echo "All pre-push checks passed!"