Makefile 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. .PHONY: check check-fmt check-test check-clippy check-lines fmt clippy test addon-image addon-push help
  2. # Run all quality gates (delegates to the shared script for use in CI).
  3. check:
  4. @./scripts/check.sh
  5. # Individual gates (for iterating on a single failure).
  6. check-fmt:
  7. cargo fmt --check
  8. check-test:
  9. cargo test
  10. check-clippy:
  11. cargo clippy --all-targets -- -D warnings
  12. # Ensure no Rust source file exceeds 500 lines (see AGENTS.md).
  13. check-lines:
  14. @exit_code=0; \
  15. max=500; \
  16. for f in src/**/*.rs src/*.rs; do \
  17. [ -f "$$f" ] || continue; \
  18. lines=$$(wc -l < "$$f"); \
  19. if [ "$$lines" -gt "$$max" ]; then \
  20. echo "FAIL: $$f has $$lines lines (max $$max)"; \
  21. exit_code=1; \
  22. fi; \
  23. done; \
  24. if [ "$$exit_code" -eq 0 ]; then \
  25. echo "✅ All Rust source files are under $$max lines"; \
  26. else \
  27. exit "$$exit_code"; \
  28. fi
  29. # Auto-fix formatting (not a gate; use sparingly before committing).
  30. fmt:
  31. cargo fmt --all
  32. # The sm121 HA add-on image (the sibling sm121-ha-integration repo is the
  33. # HA add-on store: repository.json + sm121/ + the GitHub Actions
  34. # workflows). Multi-stage: rust:alpine compiles sm121 from launcher-src/
  35. # (this repo, rsynced into the build context) with a trivial
  36. # `cargo build --release` (pinned rust:alpine, native arch, dynamic musl);
  37. # the alpine final image ships it (~25 MB — no toolchain, no
  38. # compile-on-boot: a 4 GB Pi must not OOM on a release build).
  39. # Smoke test: scripts/smoke-addon.sh.
  40. # CI (sm121-ha-integration) builds + publishes ghcr.io/kilork/sm121-addon
  41. # (aarch64 + amd64 + multi-arch manifest, OIDC — no docker login) on
  42. # push to main. The GHCR package must be set public (first time only).
  43. # Local build for dev / smoke:
  44. addon-image:
  45. rm -rf ../sm121-ha-integration/launcher-src
  46. rsync -a --exclude .git --exclude target ./ ../sm121-ha-integration/launcher-src/
  47. docker build -t sm121-addon:latest -f ../sm121-ha-integration/sm121/Dockerfile ../sm121-ha-integration/
  48. # Auto-fix lints (clippy --fix); review the diff before committing.
  49. clippy-fix:
  50. cargo clippy --all-targets --fix --allow-dirty --allow-staged
  51. help:
  52. @echo "make check Run all quality gates (fmt, test, clippy, lines)"
  53. @echo "make check-fmt Run cargo fmt --check"
  54. @echo "make check-test Run cargo test"
  55. @echo "make check-clippy Run cargo clippy --all-targets -- -D warnings"
  56. @echo "make check-lines Verify all src/**/*.rs are ≤500 lines"
  57. @echo "make fmt Auto-fix formatting"
  58. @echo "make clippy-fix Apply clippy suggestions (review diff)"