Skip to content

Commit f85731c

Browse files
committed
build(proto): switch to buf and gate gen on breaking check
Replace protoc-based proto/Makefile with buf (v1.55.1). `make -C proto gen` now runs `buf breaking` against main before `buf generate`, so wire- incompatible changes fail locally before regenerating. Add a Proto workflow that runs the same breaking check, regenerates, and fails if the committed *.pb.go drift from the generated output. Regenerate all *.pb.go under buf; the only functional diff is normalized internal symbol names in internal.pb.go (no exported API change).
1 parent 830c3e5 commit f85731c

14 files changed

Lines changed: 161 additions & 92 deletions

.github/workflows/proto.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
on:
2+
push:
3+
paths:
4+
- 'proto/**'
5+
- '.github/workflows/proto.yml'
6+
pull_request:
7+
paths:
8+
- 'proto/**'
9+
- '.github/workflows/proto.yml'
10+
11+
name: Proto
12+
permissions:
13+
contents: read
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
proto:
21+
runs-on: ubuntu-latest
22+
env:
23+
BUF_VERSION: 1.55.1
24+
PROTOC_GEN_GO_VERSION: v1.36.11
25+
PROTOC_GEN_GO_GRPC_VERSION: v1.6.1
26+
steps:
27+
- uses: actions/checkout@v6
28+
with:
29+
fetch-depth: 0
30+
- uses: actions/setup-go@v6
31+
with:
32+
go-version-file: 'go.mod'
33+
- name: Install buf
34+
run: go install github.com/bufbuild/buf/cmd/buf@v${{ env.BUF_VERSION }}
35+
- name: Install protoc-gen-go
36+
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@${{ env.PROTOC_GEN_GO_VERSION }}
37+
- name: Install protoc-gen-go-grpc
38+
run: go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${{ env.PROTOC_GEN_GO_GRPC_VERSION }}
39+
- name: buf breaking (against main)
40+
if: github.ref != 'refs/heads/main'
41+
working-directory: proto
42+
run: buf breaking --against '../.git#subdir=proto,branch=main'
43+
- name: buf generate
44+
working-directory: proto
45+
run: buf generate
46+
- name: Fail on regenerated diff
47+
run: |
48+
if ! git diff --exit-code -- proto/; then
49+
echo "::error::Generated proto files differ from committed output. Run 'make -C proto gen' and commit the result."
50+
exit 1
51+
fi
52+
- name: go build
53+
run: go build ./...

proto/Makefile

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
PROTOC_VERSION := libprotoc 29.3
2-
PROTOC_GEN_GO_VERSION := protoc-gen-go v1.36.11
3-
PROTOC_GEN_GO_GRPC_VERSION := protoc-gen-go-grpc 1.6.1
1+
BUF_VERSION := 1.55.1
2+
PROTOC_GEN_GO_VERSION := v1.36.11
3+
PROTOC_GEN_GO_GRPC_VERSION := 1.6.1
44

5-
.PHONY: all gen check-tools
5+
BUF ?= buf
6+
BREAKING_AGAINST ?= ../.git#subdir=proto,branch=main
7+
8+
.PHONY: all gen check-tools breaking
69

710
all: gen
811

912
check-tools:
10-
@if [ "$$(protoc --version)" != "$(PROTOC_VERSION)" ]; then \
11-
echo "expected $(PROTOC_VERSION), got $$(protoc --version)"; \
13+
@command -v $(BUF) >/dev/null 2>&1 || { \
14+
echo "buf not found; install with:"; \
15+
echo " go install github.com/bufbuild/buf/cmd/buf@v$(BUF_VERSION)"; \
1216
exit 1; \
17+
}
18+
@installed_buf=$$($(BUF) --version 2>/dev/null); \
19+
if [ "$$installed_buf" != "$(BUF_VERSION)" ]; then \
20+
echo "warning: buf version mismatch (expected $(BUF_VERSION), got $$installed_buf)"; \
1321
fi
14-
@if [ "$$(protoc-gen-go --version)" != "$(PROTOC_GEN_GO_VERSION)" ]; then \
15-
echo "expected $(PROTOC_GEN_GO_VERSION), got $$(protoc-gen-go --version)"; \
22+
@command -v protoc-gen-go >/dev/null 2>&1 || { \
23+
echo "protoc-gen-go not found; install with:"; \
24+
echo " go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)"; \
1625
exit 1; \
17-
fi
18-
@if [ "$$(protoc-gen-go-grpc --version)" != "$(PROTOC_GEN_GO_GRPC_VERSION)" ]; then \
19-
echo "expected $(PROTOC_GEN_GO_GRPC_VERSION), got $$(protoc-gen-go-grpc --version)"; \
26+
}
27+
@command -v protoc-gen-go-grpc >/dev/null 2>&1 || { \
28+
echo "protoc-gen-go-grpc not found; install with:"; \
29+
echo " go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v$(PROTOC_GEN_GO_GRPC_VERSION)"; \
2030
exit 1; \
31+
}
32+
33+
breaking: check-tools
34+
@if git -C .. rev-parse --verify main >/dev/null 2>&1; then \
35+
$(BUF) breaking --against '$(BREAKING_AGAINST)'; \
36+
else \
37+
echo "skip breaking check: main branch not found"; \
2138
fi
2239

23-
gen: check-tools
24-
protoc --go_out=. --go_opt=paths=source_relative \
25-
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
26-
service.proto
27-
protoc --go_out=. --go_opt=paths=source_relative \
28-
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
29-
internal.proto
30-
protoc --go_out=. --go_opt=paths=source_relative \
31-
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
32-
distribution.proto
33-
protoc --go_out=. --go_opt=paths=source_relative \
34-
dynamodb_internal.proto
35-
protoc --go_out=. --go_opt=paths=source_relative \
36-
redis_internal.proto
37-
protoc --go_out=. --go_opt=paths=source_relative \
38-
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
39-
etcd_raft.proto
40+
gen: check-tools breaking
41+
$(BUF) generate

proto/buf.gen.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: v2
2+
plugins:
3+
- local: protoc-gen-go
4+
out: .
5+
opt: paths=source_relative
6+
- local: protoc-gen-go-grpc
7+
out: .
8+
opt: paths=source_relative

proto/buf.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: v2
2+
modules:
3+
- path: .
4+
breaking:
5+
use:
6+
- FILE

proto/distribution.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/distribution_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/dynamodb_internal.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/etcd_raft.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/etcd_raft_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)