check.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env bash
  2. # Run all quality gates for the sm121 launcher (see AGENTS.md and Makefile):
  3. #
  4. # 1. cargo fmt --check (formatting)
  5. # 2. cargo clippy --all-targets -- -D warnings (lints, warnings-as-errors)
  6. # 3. cargo test (unit tests)
  7. # 4. file-size check (no src/**/*.rs > 500 lines)
  8. #
  9. # Fails fast on the first failed gate so devs see one problem at a time.
  10. # Wire into CI by running `./scripts/check.sh`; locally use `make check`.
  11. set -euo pipefail
  12. cd "$(dirname "$0")/.."
  13. # Color output if stderr is a tty.
  14. if [ -t 2 ]; then
  15. RED=$'\033[31m'; GREEN=$'\033[32m'; YELLOW=$'\033[33m'; RESET=$'\033[0m'
  16. else
  17. RED=""; GREEN=""; YELLOW=""; RESET=""
  18. fi
  19. step() { printf '%s==> %s%s\n' "$YELLOW" "$*" "$RESET" >&2; }
  20. ok() { printf '%s ✓ %s%s\n' "$GREEN" "$*" "$RESET" >&2; }
  21. die() { printf '%s ✗ %s%s\n' "$RED" "$*" "$RESET" >&2; exit 1; }
  22. # 1. Formatting
  23. step "cargo fmt --check"
  24. if cargo fmt --check; then
  25. ok "fmt"
  26. else
  27. die "cargo fmt --check failed — run 'cargo fmt' or 'make fmt' to fix"
  28. fi
  29. # 2. Lints (treat warnings as errors)
  30. step "cargo clippy --all-targets -- -D warnings"
  31. if cargo clippy --all-targets -- -D warnings; then
  32. ok "clippy"
  33. else
  34. die "cargo clippy failed"
  35. fi
  36. # 3. Tests
  37. step "cargo test"
  38. if cargo test; then
  39. ok "test"
  40. else
  41. die "cargo test failed"
  42. fi
  43. # 4. File size (AGENTS.md: no src file >500 lines)
  44. step "src/**/*.rs ≤ 500 lines"
  45. max=500
  46. exit_code=0
  47. while IFS= read -r f; do
  48. [ -f "$f" ] || continue
  49. lines=$(wc -l < "$f")
  50. if [ "$lines" -gt "$max" ]; then
  51. printf '%s ✗ %s has %s lines (max %s)%s\n' "$RED" "$f" "$lines" "$max" "$RESET" >&2
  52. exit_code=1
  53. fi
  54. done < <(find src -type f -name '*.rs')
  55. if [ "$exit_code" -eq 0 ]; then
  56. ok "lines"
  57. else
  58. exit 1
  59. fi
  60. echo
  61. printf '%sAll gates passed.%s\n' "$GREEN" "$RESET"