From a65d7a922cab65b80f1b732248cf0cce8312da69 Mon Sep 17 00:00:00 2001 From: manjari Date: Tue, 13 Oct 2026 19:10:48 +0000 Subject: [PATCH] build(mocks): Generate mocks with the pinned mockgen and check them in CI --- .github/workflows/ci.yml | 5 ++++- Makefile | 7 +++++-- doc/howto/DEVELOPMENT.md | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c752d9b2..fda75a5ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,7 +47,7 @@ jobs: run: make lint # --------------------------------------------------------------------------- - # TIDY (module files + BUILD files in sync) + # TIDY (module files + BUILD files + mocks in sync) # --------------------------------------------------------------------------- tidy: name: Tidy @@ -67,6 +67,9 @@ jobs: - name: Check BUILD files are up to date run: make check-gazelle + - name: Check mocks are up to date + run: make check-mocks + # --------------------------------------------------------------------------- # BUILD AND UNIT TESTS (parallel jobs, separate Bazel caches) # --------------------------------------------------------------------------- diff --git a/Makefile b/Makefile index 418f46ff8..5ca54ae72 100644 --- a/Makefile +++ b/Makefile @@ -631,9 +631,12 @@ GO_GENERATE_PACKAGES := \ ./submitqueue/gateway/extension/storage/... \ ./submitqueue/orchestrator/extension/storage/... -mocks: ## Generate mock files using mockgen +mocks: ## Generate mock files using the pinned mockgen @echo "Generating mocks..." - @$(BAZEL) run @rules_go//go -- generate $(GO_GENERATE_PACKAGES) + @$(BAZEL) build @org_uber_go_mock//mockgen + @mkdir -p bin/mockgen + @cp -f "$$($(BAZEL) cquery --output=files @org_uber_go_mock//mockgen 2>/dev/null)" bin/mockgen/mockgen + @PATH="$(CURDIR)/bin/mockgen:$$PATH" $(BAZEL) run @rules_go//go -- generate $(GO_GENERATE_PACKAGES) @echo "Mocks generated successfully!" proto: ## Generate protobuf files from .proto definitions diff --git a/doc/howto/DEVELOPMENT.md b/doc/howto/DEVELOPMENT.md index 4586a9d25..f17108740 100644 --- a/doc/howto/DEVELOPMENT.md +++ b/doc/howto/DEVELOPMENT.md @@ -92,7 +92,7 @@ brew install grpcurl `make help` lists every target. The table below is the day-to-day set. -CI runs `make lint`, `make check-tidy`, and `make check-gazelle`. `make lint` includes the format check, license headers, the tracked-binary check, the message-ID check, and the queue-shard check. `make fmt`, `make tidy`, and `make gazelle` apply the corresponding fixes. `make mocks` regenerates the checked-in mockgen files; `make check-mocks` fails when that output differs from the tree. `make clean` removes the Bazel cache and `bin/`. Generated protobuf Go files stay in the source tree until `make clean-proto`; `make proto` writes them again. +CI runs `make lint`, `make check-tidy`, `make check-gazelle`, and `make check-mocks`. `make lint` includes the format check, license headers, the tracked-binary check, the message-ID check, and the queue-shard check. `make fmt`, `make tidy`, and `make gazelle` apply the corresponding fixes. `make mocks` regenerates the checked-in mockgen files with the `mockgen` pinned in `go.mod`, which Bazel builds into `bin/mockgen/` and puts first on `PATH`, so no local install is needed and a different `mockgen` on your `PATH` is ignored; run `go generate` directly only with that binary on `PATH`. `make check-mocks` fails when that output differs from the tree. `make clean` removes the Bazel cache and `bin/`. Generated protobuf Go files stay in the source tree until `make clean-proto`; `make proto` writes them again. | Target | Description | |--------|-------------|