diff --git a/.github/workflows/test-and-build.yml b/.github/workflows/test-and-build.yml index ca634384..2dd8613e 100644 --- a/.github/workflows/test-and-build.yml +++ b/.github/workflows/test-and-build.yml @@ -51,6 +51,9 @@ jobs: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + - name: Check go mod tidy + run: make check-go-mod-tidy + - name: Build Rust library run: make rust diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4264f330..03f4f3e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -222,6 +222,10 @@ pre-commit run --all-files - Use meaningful variable and function names - Add comments for exported functions and types - Write unit tests for new functionality +- **Keep Go modules tidy:** Run `go mod tidy` in the appropriate directory after adding or removing dependencies + - For `candle-binding`: `cd candle-binding && go mod tidy` + - For `src/semantic-router`: `cd src/semantic-router && go mod tidy` + - The CI will automatically check that `go.mod` and `go.sum` files are tidy using `make check-go-mod-tidy` ### Rust Code - Follow Rust formatting (`cargo fmt`) @@ -242,6 +246,11 @@ pre-commit run --all-files python e2e-tests/run_all_tests.py ``` + The `make test` command includes: + - `go vet` for static analysis + - `check-go-mod-tidy` for Go module dependency verification + - Unit tests for all components + 2. **Create a pull request** with: - Clear description of changes - Reference to any related issues diff --git a/Makefile b/Makefile index d8526242..9f3f4258 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,24 @@ vet: @cd candle-binding && go vet ./... @cd src/semantic-router && go vet ./... +# Check go mod tidy for all Go modules +check-go-mod-tidy: + @echo "Checking go mod tidy for all Go modules..." + @echo "Checking candle-binding..." + @cd candle-binding && go mod tidy && \ + (git diff --exit-code go.mod 2>/dev/null || (echo "ERROR: go.mod file is not tidy in candle-binding. Please run 'go mod tidy' in candle-binding directory and commit the changes." && git diff go.mod && exit 1)) && \ + (test ! -f go.sum || git diff --exit-code go.sum 2>/dev/null || (echo "ERROR: go.sum file is not tidy in candle-binding. Please run 'go mod tidy' in candle-binding directory and commit the changes." && git diff go.sum && exit 1)) + @echo "✅ candle-binding go mod tidy check passed" + @echo "Checking src/semantic-router..." + @cd src/semantic-router && go mod tidy && \ + if ! git diff --exit-code go.mod go.sum; then \ + echo "ERROR: go.mod or go.sum files are not tidy in src/semantic-router. Please run 'go mod tidy' in src/semantic-router directory and commit the changes."; \ + git diff go.mod go.sum; \ + exit 1; \ + fi + @echo "✅ src/semantic-router go mod tidy check passed" + @echo "✅ All go mod tidy checks passed" + # Test the Rust library test-binding: rust @echo "Running Go tests with static library..." @@ -92,7 +110,7 @@ test-semantic-router: build-router cd src/semantic-router && CGO_ENABLED=1 go test -v ./... # Test the Rust library and the Go binding -test: vet download-models test-binding test-semantic-router +test: vet check-go-mod-tidy download-models test-binding test-semantic-router # Clean built artifacts clean: diff --git a/src/semantic-router/go.mod b/src/semantic-router/go.mod index 0e6aaf98..7c4e59f7 100644 --- a/src/semantic-router/go.mod +++ b/src/semantic-router/go.mod @@ -10,11 +10,13 @@ replace ( require ( github.com/envoyproxy/go-control-plane/envoy v1.32.4 + github.com/fsnotify/fsnotify v1.7.0 github.com/onsi/ginkgo/v2 v2.23.4 github.com/onsi/gomega v1.38.0 github.com/openai/openai-go v1.12.0 github.com/prometheus/client_golang v1.23.0 github.com/vllm-project/semantic-router/candle-binding v0.0.0-00010101000000-000000000000 + go.uber.org/zap v1.27.0 google.golang.org/grpc v1.71.1 gopkg.in/yaml.v3 v3.0.1 ) @@ -24,7 +26,6 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cncf/xds/go v0.0.0-20241223141626-cff3c89139a3 // indirect github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/google/go-cmp v0.7.0 // indirect @@ -41,7 +42,6 @@ require ( github.com/tidwall/sjson v1.2.5 // indirect go.uber.org/automaxprocs v1.6.0 // indirect go.uber.org/multierr v1.10.0 // indirect - go.uber.org/zap v1.27.0 // indirect golang.org/x/net v0.41.0 // indirect golang.org/x/sys v0.33.0 // indirect golang.org/x/text v0.26.0 // indirect