From 1fd944eec713d588f553556aed70e8b6427e7060 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Wed, 24 Sep 2025 11:40:24 -0400 Subject: [PATCH 1/4] Fix generation and add check to CI This fixes `just generate` and adds a justfile target to check that generation doesn't change files in CI (we do [something similar in protovalidate-python][1] and I used the same logic). I also added comments to the justfile targets so `just --list` has a short description. [1]: https://github.com/bufbuild/protovalidate-python/blob/1f0d1837077765e4c21933202594bddb9f065b5a/Makefile#L72-L75 Signed-off-by: Stefan VanBuren --- .github/workflows/ci.yaml | 2 ++ conformance/buf.gen.yaml | 2 ++ example/buf.gen.yaml | 2 ++ justfile | 19 +++++++++++++++++++ test/buf.gen.yaml | 2 ++ 5 files changed, 27 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 749b596..1164c91 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -87,6 +87,8 @@ jobs: run: go test ./... working-directory: protoc-gen-connect-python + - run: uv run just checkgenerate + - uses: codecov/codecov-action@v5 if: ${{ matrix.coverage == 'cov' }} diff --git a/conformance/buf.gen.yaml b/conformance/buf.gen.yaml index f68e2eb..ac37db9 100644 --- a/conformance/buf.gen.yaml +++ b/conformance/buf.gen.yaml @@ -9,7 +9,9 @@ plugins: - local: - go - run + - -C - ../protoc-gen-connect-python + - . out: test/gen opt: - imports=relative diff --git a/example/buf.gen.yaml b/example/buf.gen.yaml index ba9fa2e..8d1e4fb 100644 --- a/example/buf.gen.yaml +++ b/example/buf.gen.yaml @@ -7,5 +7,7 @@ plugins: - local: - go - run + - -C - ../protoc-gen-connect-python + - . out: . diff --git a/justfile b/justfile index 352d76c..6d8aaee 100644 --- a/justfile +++ b/justfile @@ -1,39 +1,51 @@ +# https://just.systems/ + BUF_VERSION := "v1.57.0" [private] @default: check +# Format Python files format: uv run ruff check --fix . uv run ruff format . +# Lint Python files lint: uv run ruff format --check . uv run ruff check . +# Typecheck Python files typecheck: uv run pyright +# Run unit tests with no extras [working-directory: 'noextras'] test-noextras *args: uv run --exact pytest {{args}} +# Run unit tests test *args: (test-noextras args) uv run pytest {{args}} +# Run lint, typecheck and test check: lint typecheck test +# Run conformance tests [working-directory: 'conformance'] conformance *args: uv run pytest {{args}} +# Build docs docs: uv run mkdocs build +# Serve the docs locally [working-directory: 'site'] docs-serve: docs uv run python -m http.server 8000 +# Generate conformance files [working-directory: 'conformance'] generate-conformance: go run github.com/bufbuild/buf/cmd/buf@{{BUF_VERSION}} generate @@ -42,12 +54,19 @@ generate-conformance: @# structure, we use sed to fix the imports instead. LC_ALL=c find test/gen -type f -exec sed -i '' 's/from connectrpc.conformance.v1/from gen.connectrpc.conformance.v1/' {} + +# Generate example files [working-directory: 'example'] generate-example: go run github.com/bufbuild/buf/cmd/buf@{{BUF_VERSION}} generate +# Generate test files [working-directory: 'test'] generate-test: go run github.com/bufbuild/buf/cmd/buf@{{BUF_VERSION}} generate +# Run all generation targets, and format the generated code generate: generate-conformance generate-example generate-test format + +# Used in CI to verify that `just generate` doesn't produce a diff +checkgenerate: generate + test -z "$$(git status --porcelain | tee /dev/stderr)" diff --git a/test/buf.gen.yaml b/test/buf.gen.yaml index 6c23e84..d9c826c 100644 --- a/test/buf.gen.yaml +++ b/test/buf.gen.yaml @@ -7,7 +7,9 @@ plugins: - local: - go - run + - -C - ../protoc-gen-connect-python + - . out: . opt: - imports=relative From aab6b1f38f868d0162eb5ab83797219e512f1983 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Wed, 24 Sep 2025 11:46:23 -0400 Subject: [PATCH 2/4] Only run checkgenerate on ubuntu Shouldn't change based on OS, similar to how we have the lint step. And add a simple name to the step. Signed-off-by: Stefan VanBuren --- .github/workflows/ci.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1164c91..a553694 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -87,7 +87,9 @@ jobs: run: go test ./... working-directory: protoc-gen-connect-python - - run: uv run just checkgenerate + - name: check running `just generate` does not create a diff + if: startsWith(matrix.os, 'ubuntu-') + run: uv run just checkgenerate - uses: codecov/codecov-action@v5 if: ${{ matrix.coverage == 'cov' }} From 66571898bc291d2a0be6ab41012f4d4593e91186 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Wed, 24 Sep 2025 12:03:29 -0400 Subject: [PATCH 3/4] Switch to using macOS for checkgenerate `sed` differences :( Signed-off-by: Stefan VanBuren --- .github/workflows/ci.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a553694..f1907eb 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -88,7 +88,8 @@ jobs: working-directory: protoc-gen-connect-python - name: check running `just generate` does not create a diff - if: startsWith(matrix.os, 'ubuntu-') + # NOTE: running on macOS as our sed command only works there + if: startsWith(matrix.os, 'macos-') run: uv run just checkgenerate - uses: codecov/codecov-action@v5 From eb3ebfc105a1d45de761e016389736d084df1a81 Mon Sep 17 00:00:00 2001 From: Stefan VanBuren Date: Wed, 24 Sep 2025 13:11:01 -0400 Subject: [PATCH 4/4] Fix Makefile syntax in justfile Signed-off-by: Stefan VanBuren --- justfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/justfile b/justfile index 6d8aaee..a13f963 100644 --- a/justfile +++ b/justfile @@ -69,4 +69,4 @@ generate: generate-conformance generate-example generate-test format # Used in CI to verify that `just generate` doesn't produce a diff checkgenerate: generate - test -z "$$(git status --porcelain | tee /dev/stderr)" + test -z "$(git status --porcelain | tee /dev/stderr)"