@@ -10,10 +10,46 @@ ORCHESTRATOR_COMPOSE_FILE = example/server/orchestrator/docker-compose.yml
1010# Fixed project name for local manual testing (tests use unique random names)
1111LOCAL_PROJECT = submitqueue
1212
13+ # Minimum overall coverage percentage (override with: make check-coverage COVERAGE_THRESHOLD=80)
14+ COVERAGE_THRESHOLD ?= 80
15+
16+ # Minimum diff coverage percentage for new/changed lines (override with: make check-coverage DIFF_COVERAGE_THRESHOLD=90)
17+ DIFF_COVERAGE_THRESHOLD ?= 85
18+
1319# Set REPO_ROOT for docker-compose
1420export REPO_ROOT := $(shell pwd)
1521
16- .PHONY : build build-all-linux build-gateway-linux build-orchestrator-linux clean clean-proto deps e2e-test gazelle integration-test integration-test-extensions integration-test-gateway integration-test-orchestrator local-clean local-gateway-start local-gateway-stop local-init-schemas local-logs local-orchestrator-start local-orchestrator-stop local-ps local-restart local-start local-stop proto query-deps query-targets run-client-gateway run-client-orchestrator run-queue-admin test test-no-cache help
22+ # Runs the coverage tool with optional diff detection.
23+ # Usage: $(call run_coverage,extra flags...)
24+ define run_coverage
25+ @LCOV=$$($(BAZEL ) info output_path) /_coverage/_coverage_report.dat; \
26+ MERGE_BASE=$$(git merge-base origin/main HEAD 2>/dev/null || echo "" ) ; \
27+ DIFF_ARGS=""; \
28+ if [ -n "$$MERGE_BASE" ] && [ "$$(git rev-parse HEAD ) " != "$$MERGE_BASE" ]; then \
29+ git diff $$MERGE_BASE HEAD > /tmp/coverage-diff.patch; \
30+ DIFF_ARGS="-diff /tmp/coverage-diff.patch"; \
31+ fi; \
32+ $(BAZEL ) run //tool/coverage -- \
33+ $$DIFF_ARGS \
34+ -summary $(CURDIR ) /coverage-html/summary.txt \
35+ -html $(CURDIR ) /coverage-html \
36+ -src $(CURDIR ) \
37+ $(1 ) \
38+ $$LCOV
39+ endef
40+
41+ # Fails if git working tree is dirty. Usage: $(call assert_clean,fix command)
42+ define assert_clean
43+ @if ! git diff --quiet; then \
44+ echo "The following files need updating:" >&2; \
45+ git diff --name-only >&2; \
46+ echo "" >&2; \
47+ echo "Please run '$(1 ) ' locally and commit the changes." >&2; \
48+ exit 1; \
49+ fi
50+ endef
51+
52+ .PHONY : build build-all-linux build-gateway-linux build-orchestrator-linux check-coverage check-gazelle check-tidy clean clean-proto coverage deps e2e-test fmt gazelle integration-test integration-test-extensions integration-test-gateway integration-test-orchestrator lint lint-fmt lint-yaml local-clean local-gateway-start local-gateway-stop local-init-schemas local-logs local-orchestrator-start local-orchestrator-stop local-ps local-restart local-start local-stop proto query-deps query-targets run-client-gateway run-client-orchestrator run-queue-admin test test-no-cache tidy tidy-bazel tidy-go help
1753
1854
1955build : # # Build all services and examples
@@ -41,6 +77,21 @@ build-orchestrator-linux: ## Build Orchestrator Linux binary for Docker
4177 cp -f bazel-bin/example/server/orchestrator/orchestrator .docker-bin/orchestrator
4278 @echo " Orchestrator Linux binary ready at .docker-bin/orchestrator"
4379
80+ check-coverage : # # Enforce coverage thresholds (overall: $(COVERAGE_THRESHOLD)%, diff: $(DIFF_COVERAGE_THRESHOLD)%)
81+ @echo " Running tests with coverage..."
82+ @$(BAZEL ) coverage //... --test_tag_filters=-manual,-integration --combined_report=lcov
83+ $(call run_coverage,-threshold $(COVERAGE_THRESHOLD ) -diff-threshold $(DIFF_COVERAGE_THRESHOLD ) )
84+
85+ check-gazelle : # # Check BUILD.bazel files are up to date
86+ @echo " Running Gazelle to check BUILD files..."
87+ @$(BAZEL ) run //:gazelle
88+ $(call assert_clean,make gazelle)
89+ @echo " BUILD files are up to date."
90+
91+ check-tidy : tidy # # Check that go.mod and MODULE.bazel are tidy
92+ $(call assert_clean,make tidy)
93+ @echo " Module files are up to date."
94+
4495clean : # # Clean generated files and binaries
4596 @echo " Cleaning with Bazel..."
4697 @$(BAZEL ) clean
@@ -53,16 +104,24 @@ clean-proto: ## Clean generated proto files
53104 @rm -rf orchestrator/protopb/* .pb.go
54105 @echo " Proto clean complete!"
55106
56- deps : # # Install Go dependencies
57- @echo " Installing Go dependencies..."
58- @go mod download
59- @go mod tidy
107+ coverage : # # Run tests with coverage, generate HTML report
108+ @echo " Running tests with coverage..."
109+ @$(BAZEL ) coverage //... --test_tag_filters=-manual,-integration --combined_report=lcov
110+ $(call run_coverage,)
111+
112+ deps : tidy-go # # Download and tidy Go dependencies
60113 @echo " Dependencies installed!"
61114
62115e2e-test : build-all-linux # # Run end-to-end tests (hermetic, auto-builds binaries)
63116 @echo " Running end-to-end tests..."
64117 @$(BAZEL ) test //test/e2e:e2e_test --test_output=streamed
65118
119+ fmt : # # Format Go code
120+ @GOFMT=$$($(BAZEL ) run @rules_go//go -- env GOROOT 2>/dev/null | tail -1) /bin/gofmt; \
121+ echo " Formatting Go code (using $$ GOFMT)..." ; \
122+ $$ GOFMT -w . ; \
123+ echo " Formatting complete!"
124+
66125gazelle : # # Update BUILD.bazel files
67126 @echo " Running Gazelle to update BUILD files..."
68127 @$(BAZEL ) run //:gazelle
@@ -83,6 +142,18 @@ integration-test-orchestrator: build-orchestrator-linux ## Run Orchestrator inte
83142 @echo " Running Orchestrator integration tests..."
84143 @$(BAZEL ) test //test/integration/orchestrator:orchestrator_test --test_output=streamed
85144
145+ lint : lint-fmt lint-yaml # # Run all linters
146+ @echo " All lint checks passed."
147+
148+ lint-fmt : fmt # # Check Go code formatting (fails if unformatted)
149+ $(call assert_clean,make fmt)
150+ @echo " All Go files are properly formatted."
151+
152+ lint-yaml : # # Check YAML files for syntax errors
153+ @echo " Checking YAML files..."
154+ @$(BAZEL ) run //tool/linter/yamllint -- .
155+ @echo " All YAML files are valid."
156+
86157local-clean : # # Stop and remove all local services, volumes, and images
87158 @echo " Cleaning all services and data..."
88159 @$(COMPOSE ) -f $(COMPOSE_FILE ) -p $(LOCAL_PROJECT ) down -v --rmi local
@@ -229,6 +300,16 @@ test-no-cache: ## Run unit tests without cache (force re-run)
229300 @echo " Running unit tests (no cache)..."
230301 @$(BAZEL ) test //... --test_tag_filters=-manual,-integration --nocache_test_results
231302
303+ tidy : tidy-go tidy-bazel # # Run go mod tidy and bazel mod tidy
304+
305+ tidy-bazel : # # Run bazel mod tidy
306+ @echo " Running bazel mod tidy..."
307+ @$(BAZEL ) mod tidy
308+
309+ tidy-go : # # Run go mod tidy
310+ @echo " Running go mod tidy..."
311+ @$(BAZEL ) run @rules_go//go -- mod tidy -e
312+
232313help : # # Show this help message
233314 @echo " Available targets:"
234315 @echo " "
0 commit comments