-
Notifications
You must be signed in to change notification settings - Fork 2
build(proto): switch to buf and gate gen on breaking check #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f85731c
bee4bef
8519195
7babe86
d917069
944820d
25217e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| on: | ||
| push: | ||
| paths: | ||
| - 'proto/**' | ||
| - '.github/workflows/proto.yml' | ||
| pull_request: | ||
| paths: | ||
| - 'proto/**' | ||
| - '.github/workflows/proto.yml' | ||
|
|
||
| name: Proto | ||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| proto: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| BUF_VERSION: 1.55.1 | ||
| PROTOC_GEN_GO_VERSION: v1.36.11 | ||
| PROTOC_GEN_GO_GRPC_VERSION: v1.6.1 | ||
| steps: | ||
| # actions/checkout v6 | ||
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
| - name: Fetch main for breaking baseline | ||
| if: github.ref != 'refs/heads/main' | ||
| run: git fetch --no-tags --prune origin +refs/heads/main:refs/heads/buf-breaking-base | ||
| # actions/setup-go v6 | ||
| - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c | ||
| with: | ||
| go-version-file: 'go.mod' | ||
| - name: Install buf | ||
| run: go install github.com/bufbuild/buf/cmd/buf@v${{ env.BUF_VERSION }} | ||
| - name: Install protoc-gen-go | ||
| run: go install google.golang.org/protobuf/cmd/protoc-gen-go@${{ env.PROTOC_GEN_GO_VERSION }} | ||
| - name: Install protoc-gen-go-grpc | ||
| run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${{ env.PROTOC_GEN_GO_GRPC_VERSION }} | ||
| - name: buf breaking (against main) | ||
| if: github.ref != 'refs/heads/main' | ||
| working-directory: proto | ||
| run: buf breaking --against '../.git#subdir=proto,branch=buf-breaking-base' | ||
| - name: Clean generated proto outputs | ||
| run: find proto -maxdepth 1 -type f \( -name '*.pb.go' -o -name '*_grpc.pb.go' \) -delete | ||
| - name: buf generate | ||
| working-directory: proto | ||
| run: buf generate | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because this runs a plain Useful? React with 👍 / 👎. |
||
| - name: Fail on regenerated diff | ||
| run: | | ||
| # intent-to-add surfaces newly generated .pb.go that would | ||
| # otherwise be invisible to `git diff` (adding a .proto without | ||
| # committing its generated .pb.go must fail this gate). | ||
| git add -N proto/ | ||
| if ! git diff --exit-code -- proto/; then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The Useful? React with 👍 / 👎. |
||
| echo "::error::Generated proto files differ from committed output. Run 'make -C proto gen' and commit the result." | ||
| exit 1 | ||
| fi | ||
| - name: go build | ||
| run: go build ./... | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,69 @@ | ||
| PROTOC_VERSION := libprotoc 29.3 | ||
| PROTOC_GEN_GO_VERSION := protoc-gen-go v1.36.11 | ||
| PROTOC_GEN_GO_GRPC_VERSION := protoc-gen-go-grpc 1.6.1 | ||
| BUF_VERSION := 1.55.1 | ||
| PROTOC_GEN_GO_VERSION := 1.36.11 | ||
| PROTOC_GEN_GO_GRPC_VERSION := 1.6.1 | ||
|
|
||
| .PHONY: all gen check-tools | ||
| BUF ?= buf | ||
| # BREAKING_AGAINST lets callers override the auto-detected baseline. | ||
| BREAKING_AGAINST ?= | ||
|
|
||
| .PHONY: all gen check-tools breaking clean-generated | ||
|
|
||
| all: gen | ||
|
|
||
| check-tools: | ||
| @if [ "$$(protoc --version)" != "$(PROTOC_VERSION)" ]; then \ | ||
| echo "expected $(PROTOC_VERSION), got $$(protoc --version)"; \ | ||
| @command -v $(BUF) >/dev/null 2>&1 || { \ | ||
| echo "buf not found; install with:"; \ | ||
| echo " go install github.com/bufbuild/buf/cmd/buf@v$(BUF_VERSION)"; \ | ||
| exit 1; \ | ||
| } | ||
| @installed=$$($(BUF) --version 2>/dev/null); \ | ||
| if [ "$$installed" != "$(BUF_VERSION)" ]; then \ | ||
| echo "buf version mismatch: expected $(BUF_VERSION), got $$installed"; \ | ||
| echo "install with: go install github.com/bufbuild/buf/cmd/buf@v$(BUF_VERSION)"; \ | ||
| exit 1; \ | ||
| fi | ||
| @if [ "$$(protoc-gen-go --version)" != "$(PROTOC_GEN_GO_VERSION)" ]; then \ | ||
| echo "expected $(PROTOC_GEN_GO_VERSION), got $$(protoc-gen-go --version)"; \ | ||
| @command -v protoc-gen-go >/dev/null 2>&1 || { \ | ||
| echo "protoc-gen-go not found; install with:"; \ | ||
| echo " go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(PROTOC_GEN_GO_VERSION)"; \ | ||
| exit 1; \ | ||
| } | ||
| @installed=$$(protoc-gen-go --version 2>/dev/null); \ | ||
| if [ "$$installed" != "protoc-gen-go v$(PROTOC_GEN_GO_VERSION)" ]; then \ | ||
| echo "protoc-gen-go version mismatch: expected v$(PROTOC_GEN_GO_VERSION), got $$installed"; \ | ||
| echo "install with: go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(PROTOC_GEN_GO_VERSION)"; \ | ||
| exit 1; \ | ||
| fi | ||
| @if [ "$$(protoc-gen-go-grpc --version)" != "$(PROTOC_GEN_GO_GRPC_VERSION)" ]; then \ | ||
| echo "expected $(PROTOC_GEN_GO_GRPC_VERSION), got $$(protoc-gen-go-grpc --version)"; \ | ||
| @command -v protoc-gen-go-grpc >/dev/null 2>&1 || { \ | ||
| echo "protoc-gen-go-grpc not found; install with:"; \ | ||
| echo " go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v$(PROTOC_GEN_GO_GRPC_VERSION)"; \ | ||
| exit 1; \ | ||
| } | ||
| @installed=$$(protoc-gen-go-grpc --version 2>/dev/null); \ | ||
| if [ "$$installed" != "protoc-gen-go-grpc $(PROTOC_GEN_GO_GRPC_VERSION)" ]; then \ | ||
| echo "protoc-gen-go-grpc version mismatch: expected $(PROTOC_GEN_GO_GRPC_VERSION), got $$installed"; \ | ||
| echo "install with: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v$(PROTOC_GEN_GO_GRPC_VERSION)"; \ | ||
| exit 1; \ | ||
| fi | ||
|
|
||
| gen: check-tools | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| --go-grpc_out=. --go-grpc_opt=paths=source_relative \ | ||
| service.proto | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| --go-grpc_out=. --go-grpc_opt=paths=source_relative \ | ||
| internal.proto | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| --go-grpc_out=. --go-grpc_opt=paths=source_relative \ | ||
| distribution.proto | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| --go-grpc_out=. --go-grpc_opt=paths=source_relative \ | ||
| admin.proto | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| dynamodb_internal.proto | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| redis_internal.proto | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| --go-grpc_out=. --go-grpc_opt=paths=source_relative \ | ||
| etcd_raft.proto | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| --go-grpc_out=. --go-grpc_opt=paths=source_relative \ | ||
| admin_forward.proto | ||
| protoc --go_out=. --go_opt=paths=source_relative \ | ||
| --go-grpc_out=. --go-grpc_opt=paths=source_relative \ | ||
| encryption_admin.proto | ||
| breaking: check-tools | ||
| @baseline='$(BREAKING_AGAINST)'; \ | ||
| if [ -z "$$baseline" ]; then \ | ||
| if git -C .. rev-parse --verify origin/main >/dev/null 2>&1; then \ | ||
| git -C .. branch --force buf-breaking-base origin/main >/dev/null; \ | ||
| baseline='../.git#subdir=proto,branch=buf-breaking-base'; \ | ||
| elif git -C .. rev-parse --verify main >/dev/null 2>&1; then \ | ||
| baseline='../.git#subdir=proto,branch=main'; \ | ||
| else \ | ||
| echo "no breaking baseline found: neither 'main' nor 'origin/main' is reachable"; \ | ||
| echo "fetch main first (git fetch origin main) or override with BREAKING_AGAINST=..."; \ | ||
| exit 1; \ | ||
| fi; \ | ||
| fi; \ | ||
| $(BUF) breaking --against "$$baseline" | ||
|
|
||
| clean-generated: | ||
| find . -maxdepth 1 -type f \( -name '*.pb.go' -o -name '*_grpc.pb.go' \) -delete | ||
|
|
||
| gen: check-tools breaking | ||
| $(MAKE) clean-generated | ||
| $(BUF) generate |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| version: v2 | ||
| plugins: | ||
| - local: protoc-gen-go | ||
| out: . | ||
| opt: paths=source_relative | ||
| - local: protoc-gen-go-grpc | ||
| out: . | ||
| opt: paths=source_relative |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| version: v2 | ||
| modules: | ||
| - path: . | ||
| breaking: | ||
| use: | ||
| - WIRE | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Using only Useful? React with 👍 / 👎. |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,5 +80,3 @@ message RelayPublishResponse { | |
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a
.protofile is removed or renamed, this in-placebuf generateleaves the old tracked*.pb.goand*_grpc.pb.gofiles untouched; because those files are already tracked and unchanged, the latergit add -N/git diff -- proto/still exits successfully and stale generated APIs can remain committed. Clean or explicitly remove only the generated outputs before regenerating so deletions are surfaced by the drift check.Useful? React with 👍 / 👎.