Files
mux/check.sh

159 lines
3.5 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_step() {
echo -e "${BLUE}==>${NC} $1"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
# Check if required tools are installed
check_tools() {
local missing_tools=()
if ! command -v staticcheck &> /dev/null; then
missing_tools+=("staticcheck")
fi
if ! command -v fieldalignment &> /dev/null; then
missing_tools+=("fieldalignment")
fi
if [ ${#missing_tools[@]} -ne 0 ]; then
print_warning "Missing tools: ${missing_tools[*]}"
echo "Install them with: make install-tools"
echo ""
fi
}
# Track overall status
FAILED=0
echo ""
echo "======================================"
echo " Mux - Code Quality Checks"
echo "======================================"
echo ""
check_tools
# Step 1: go vet
print_step "Running go vet..."
if go vet ./... 2>&1; then
print_success "go vet passed"
else
print_error "go vet failed"
FAILED=1
fi
echo ""
# Step 2: staticcheck (if available)
if command -v staticcheck &> /dev/null; then
print_step "Running staticcheck..."
if staticcheck ./... 2>&1; then
print_success "staticcheck passed"
else
print_error "staticcheck failed"
FAILED=1
fi
echo ""
else
print_warning "staticcheck not installed, skipping"
echo ""
fi
# Step 3: fieldalignment (if available)
if command -v fieldalignment &> /dev/null; then
print_step "Checking field alignment..."
ALIGNMENT_OUTPUT=$(fieldalignment ./... 2>&1 || true)
if echo "$ALIGNMENT_OUTPUT" | grep -q ":"; then
print_error "Field alignment issues found:"
echo "$ALIGNMENT_OUTPUT"
echo ""
echo "Run 'make fieldalignment-fix' or 'fieldalignment -fix ./...' to fix automatically"
FAILED=1
else
print_success "No field alignment issues found"
fi
echo ""
else
print_warning "fieldalignment not installed, skipping"
echo ""
fi
# Step 4: Run tests
print_step "Running tests..."
if go test -v ./...; then
print_success "All tests passed"
else
print_error "Tests failed"
FAILED=1
fi
echo ""
# Step 5: Run tests with race detector
print_step "Running tests with race detector..."
if go test -race ./... > /dev/null 2>&1; then
print_success "Race detector passed"
else
print_error "Race detector found issues"
FAILED=1
fi
echo ""
# Step 6: Check formatting
print_step "Checking code formatting..."
UNFORMATTED=$(gofmt -l . 2>&1 || true)
if [ -z "$UNFORMATTED" ]; then
print_success "Code is properly formatted"
else
print_error "Code is not formatted properly:"
echo "$UNFORMATTED"
echo ""
echo "Run 'make fmt' or 'gofmt -w .' to fix formatting"
FAILED=1
fi
echo ""
# Step 7: Check go.mod
print_step "Checking go.mod..."
if go mod tidy -diff > /dev/null 2>&1; then
print_success "go.mod is tidy"
else
print_warning "go.mod needs tidying"
echo "Run 'make tidy' or 'go mod tidy' to fix"
echo ""
fi
# Final result
echo "======================================"
if [ $FAILED -eq 0 ]; then
print_success "All checks passed! 🎉"
echo "======================================"
echo ""
exit 0
else
print_error "Some checks failed"
echo "======================================"
echo ""
exit 1
fi