#!/bin/bash # Quality check script for crud-pricing # # Runs all quality checks: formatting, linting, tests, and documentation generation. # This script should pass before committing changes. set -e # Exit on any error echo "========================================" echo " CRUD-PRICING QUALITY CHECKS" echo "========================================" echo "" # Color codes GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Track failures FAILED=0 # Function to run a check run_check() { local check_name=$1 local command=$2 echo -e "${YELLOW}Running: $check_name${NC}" echo "----------------------------------------" if eval "$command"; then echo -e "${GREEN}✓ $check_name passed${NC}" echo "" return 0 else echo -e "${RED}✗ $check_name failed${NC}" echo "" FAILED=1 return 1 fi } # 1. Check formatting run_check "Code formatting (rustfmt)" \ "cargo fmt -- --check" # 2. Run clippy run_check "Linting (clippy)" \ "cargo clippy --all-targets --all-features -- -D warnings" # 3. Build run_check "Build" \ "cargo build --release" # 4. Run tests run_check "Unit tests" \ "cargo test --all-features" # 5. Generate documentation run_check "Documentation generation" \ "cargo doc --no-deps --all-features" # 6. Security audit echo -e "${YELLOW}Running: Security audit (cargo audit)${NC}" echo "----------------------------------------" if cargo audit 2>&1 | grep -q "Vulnerabilities found"; then echo -e "${RED}✗ Security vulnerabilities found${NC}" cargo audit echo "" FAILED=1 else echo -e "${GREEN}✓ Security audit passed${NC}" echo "" fi # Summary echo "========================================" if [ $FAILED -eq 0 ]; then echo -e "${GREEN}✓ ALL QUALITY CHECKS PASSED${NC}" echo "========================================" exit 0 else echo -e "${RED}✗ SOME QUALITY CHECKS FAILED${NC}" echo "========================================" echo "" echo "To fix issues automatically, run: ./fix-quality.sh" exit 1 fi