rust notes

pre-push hook

make sure we add proper code before pushing and triggering ci/cd

.git/hooks/pre-push
#!/bin/bash
set -e
echo "Running Rust pre-push checks..."
# 1. Format code
echo "Formatting code..."
cargo fmt --all -- --check || (cargo fmt --all && git add -u && echo "Code was formatted. Please review changes and commit again." && exit 1)
# 2. Run clippy
echo "Running clippy..."
cargo clippy --all-targets --all-features -- -D warnings
# 3. Run tests
echo "Running tests..."
cargo test --all
# 4. Check for outdated dependencies (if cargo-outdated is installed)
if command -v cargo-outdated &> /dev/null
then
echo "Checking for outdated dependencies..."
cargo outdated --exit-code 1
else
echo "cargo-outdated is not installed. Skipping outdated dependencies check."
echo "To install, run: cargo install cargo-outdated"
fi
# 5. Run security audit (if cargo-audit is installed)
if command -v cargo-audit &> /dev/null
then
echo "Running security audit..."
cargo audit
else
echo "cargo-audit is not installed. Skipping security audit."
echo "To install, run: cargo install cargo-audit"
fi
# 6. Build documentation
echo "Building documentation..."
cargo doc --no-deps
# 7. Run benchmarks (optional, can be time-consuming)
# echo "Running benchmarks..."
# cargo bench
echo "All pre-push checks passed successfully!"

dry-run tip

call git push with --dry-run to see if the hook is working as expected