| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/usr/bin/env bash
- # Run all quality gates for the sm121 launcher (see AGENTS.md and Makefile):
- #
- # 1. cargo fmt --check (formatting)
- # 2. cargo clippy --all-targets -- -D warnings (lints, warnings-as-errors)
- # 3. cargo test (unit tests)
- # 4. file-size check (no src/**/*.rs > 500 lines)
- #
- # Fails fast on the first failed gate so devs see one problem at a time.
- # Wire into CI by running `./scripts/check.sh`; locally use `make check`.
- set -euo pipefail
- cd "$(dirname "$0")/.."
- # Color output if stderr is a tty.
- if [ -t 2 ]; then
- RED=$'\033[31m'; GREEN=$'\033[32m'; YELLOW=$'\033[33m'; RESET=$'\033[0m'
- else
- RED=""; GREEN=""; YELLOW=""; RESET=""
- fi
- step() { printf '%s==> %s%s\n' "$YELLOW" "$*" "$RESET" >&2; }
- ok() { printf '%s ✓ %s%s\n' "$GREEN" "$*" "$RESET" >&2; }
- die() { printf '%s ✗ %s%s\n' "$RED" "$*" "$RESET" >&2; exit 1; }
- # 1. Formatting
- step "cargo fmt --check"
- if cargo fmt --check; then
- ok "fmt"
- else
- die "cargo fmt --check failed — run 'cargo fmt' or 'make fmt' to fix"
- fi
- # 2. Lints (treat warnings as errors)
- step "cargo clippy --all-targets -- -D warnings"
- if cargo clippy --all-targets -- -D warnings; then
- ok "clippy"
- else
- die "cargo clippy failed"
- fi
- # 3. Tests
- step "cargo test"
- if cargo test; then
- ok "test"
- else
- die "cargo test failed"
- fi
- # 4. File size (AGENTS.md: no src file >500 lines)
- step "src/**/*.rs ≤ 500 lines"
- max=500
- exit_code=0
- while IFS= read -r f; do
- [ -f "$f" ] || continue
- lines=$(wc -l < "$f")
- if [ "$lines" -gt "$max" ]; then
- printf '%s ✗ %s has %s lines (max %s)%s\n' "$RED" "$f" "$lines" "$max" "$RESET" >&2
- exit_code=1
- fi
- done < <(find src -type f -name '*.rs')
- if [ "$exit_code" -eq 0 ]; then
- ok "lines"
- else
- exit 1
- fi
- echo
- printf '%sAll gates passed.%s\n' "$GREEN" "$RESET"
|