Skip to content

Commit 04e0810

Browse files
committed
buf: generate proto comments from BSR core module
Keep the buf.gen.yaml module version in sync with the go.mod core proto dependency. When bumping the core proto version in go.mod, the buf.gen.yaml commit hash must also be updated and `buf generate` must be run to regenerate proto comments. Includes a unit test to detect version drift between the two files.
1 parent 434f29a commit 04e0810

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

buf.gen.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ version: v2
22
managed:
33
enabled: false
44
inputs:
5-
- directory: .
5+
- module: buf.build/redpandadata/core:19149a4a2435
66
paths:
7-
- proto/redpanda/core/admin/v2/shadow_link.proto
8-
- proto/redpanda/core/common/v1/acl.proto
9-
- proto/redpanda/core/common/v1/tls.proto
7+
- redpanda/core/admin/v2/shadow_link.proto
8+
- redpanda/core/common/v1/acl.proto
9+
- redpanda/core/common/v1/tls.proto
1010
plugins:
1111
# Custom comment extraction plugin - we ONLY generate comments related files,
1212
# The rest comes from buf.build/gen/go/redpandadata/core/protocolbuffers/go
1313
- local: tools/go-comment-pbgen/run-plugin.sh
1414
out: .
1515
opt:
1616
- paths=import
17-
- Mproto/redpanda/core/admin/v2/shadow_link.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/admin/v2
18-
- Mproto/redpanda/core/common/v1/acl.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/common/v1
19-
- Mproto/redpanda/core/common/v1/tls.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/common/v1
17+
- Mredpanda/core/admin/v2/shadow_link.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/admin/v2
18+
- Mredpanda/core/common/v1/acl.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/common/v1
19+
- Mredpanda/core/common/v1/tls.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/common/v1

src/go/rpk/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
buf.build/gen/go/redpandadata/cloud/connectrpc/go v1.19.1-20251208213618-d95eb1f5bf36.2
1010
buf.build/gen/go/redpandadata/cloud/protocolbuffers/go v1.36.10-20251209175915-c155e3b17438.1
1111
buf.build/gen/go/redpandadata/common/protocolbuffers/go v1.36.10-20251106193941-bb850a944663.1
12-
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.10-20251204205609-c0c7c0a68f89.1
12+
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.11-20251218215858-19149a4a2435.1
1313
buf.build/gen/go/redpandadata/dataplane/connectrpc/go v1.19.1-20251209134521-106822fddcf0.2
1414
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.36.10-20251209134521-106822fddcf0.1
1515
buf.build/gen/go/redpandadata/gatekeeper/connectrpc/go v1.19.1-20251022210437-a5dd600d04b6.2
@@ -76,7 +76,7 @@ require (
7676
golang.org/x/term v0.36.0
7777
google.golang.org/genproto/googleapis/api v0.0.0-20251103181224-f26f9409b101
7878
google.golang.org/genproto/googleapis/rpc v0.0.0-20251029180050-ab9386a59fda
79-
google.golang.org/protobuf v1.36.10
79+
google.golang.org/protobuf v1.36.11
8080
gopkg.in/yaml.v2 v2.4.0
8181
gopkg.in/yaml.v3 v3.0.1
8282
k8s.io/api v0.33.3

src/go/rpk/go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ buf.build/gen/go/redpandadata/core/connectrpc/go v1.19.1-20251125205739-05aa34b3
1212
buf.build/gen/go/redpandadata/core/connectrpc/go v1.19.1-20251125205739-05aa34b3829a.2/go.mod h1:/y8qVz8QQFux6oxVWxu+KeC73QYqygF0wXZEIvaQU5k=
1313
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.10-20251204205609-c0c7c0a68f89.1 h1:Ya1VBu8W/qJV6ROMI4z5r1gwWDtAQaZavSe6o1o+IQk=
1414
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.10-20251204205609-c0c7c0a68f89.1/go.mod h1:QenSPzqxZpyo9hHIpRzTetvDchelVDzimnmaggHKenc=
15+
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.11-20251218215858-19149a4a2435.1 h1:LLKPTO8tKmB4nIB2WlMWavkVhRV0rWwXluy6mJfdqUM=
16+
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.11-20251218215858-19149a4a2435.1/go.mod h1:5sjUVquVwNxt3Q/EhE/UW0BBJ5sgPiaVTw8//wxRULI=
1517
buf.build/gen/go/redpandadata/dataplane/connectrpc/go v1.19.1-20251209134521-106822fddcf0.2 h1:mCwJEx9wqHwQZscE0vuW3szVb5QjlStjae5dr+gx1Lo=
1618
buf.build/gen/go/redpandadata/dataplane/connectrpc/go v1.19.1-20251209134521-106822fddcf0.2/go.mod h1:AUXVi3l4mOkfox1XUVw2U0OdvAK85qPS58RcuLnr7uM=
1719
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.36.10-20251209134521-106822fddcf0.1 h1:xjIO92l2DoT4BRdNeTOH30M+zJGCDY+sYK+t6anhfIk=
@@ -458,6 +460,8 @@ google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok=
458460
google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc=
459461
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
460462
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
463+
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
464+
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
461465
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
462466
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
463467
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

src/go/rpk/pkg/cli/shadow/config_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@
1010
package shadow
1111

1212
import (
13+
"os"
14+
"path/filepath"
15+
"regexp"
16+
"runtime"
1317
"testing"
1418

1519
"github.com/stretchr/testify/require"
1620
)
1721

22+
// findRedpandaRepoRoot searches upward from the current test file to find the
23+
// *Redpanda* repository root by looking for the .git directory.
24+
func findRedpandaRepoRoot(t *testing.T) string {
25+
_, thisFile, _, ok := runtime.Caller(1)
26+
require.True(t, ok, "failed to get current file path")
27+
dir := filepath.Dir(thisFile)
28+
for {
29+
if _, err := os.Stat(filepath.Join(dir, ".git")); err == nil {
30+
return dir
31+
}
32+
parent := filepath.Dir(dir)
33+
if parent == dir {
34+
t.Fatal("failed to find repo root (.git directory)")
35+
}
36+
dir = parent
37+
}
38+
}
39+
1840
func TestToScreamingSnakeCase(t *testing.T) {
1941
tests := []struct {
2042
name string
@@ -37,3 +59,41 @@ func TestToScreamingSnakeCase(t *testing.T) {
3759
})
3860
}
3961
}
62+
63+
// TestBufGenYamlCoreModuleVersion ensures the buf.gen.yaml module version
64+
// matches the go.mod dependency version for buf.build/gen/go/redpandadata/core.
65+
// When updating the core proto dependency in go.mod, developers must also run
66+
// `buf generate` to regenerate the proto comments.
67+
func TestBufGenYamlCoreModuleVersion(t *testing.T) {
68+
repoRoot := findRedpandaRepoRoot(t)
69+
70+
// Read buf.gen.yaml and extract the commit from:
71+
// module: buf.build/redpandadata/core:<commit>
72+
bufGenPath := filepath.Join(repoRoot, "buf.gen.yaml")
73+
bufGenContent, err := os.ReadFile(bufGenPath)
74+
require.NoError(t, err, "failed to read buf.gen.yaml")
75+
76+
bufGenRe := regexp.MustCompile(`module:\s*buf\.build/redpandadata/core:([a-f0-9]{12})`)
77+
bufGenMatch := bufGenRe.FindSubmatch(bufGenContent)
78+
require.NotNil(t, bufGenMatch, "failed to find module version in buf.gen.yaml")
79+
bufGenCommit := string(bufGenMatch[1])
80+
81+
// Read go.mod and extract the commit from:
82+
// buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.11-20251218215858-<commit>.1
83+
goModPath := filepath.Join(repoRoot, "src", "go", "rpk", "go.mod")
84+
goModContent, err := os.ReadFile(goModPath)
85+
require.NoError(t, err, "failed to read go.mod")
86+
87+
// The version format is: v<major>.<minor>.<patch>-<timestamp>-<commit>.<build>
88+
// We need to extract the 12-char commit hash before the final .<build> suffix.
89+
goModRe := regexp.MustCompile(`buf\.build/gen/go/redpandadata/core/protocolbuffers/go\s+v[0-9]+\.[0-9]+\.[0-9]+-[0-9]{14}-([a-f0-9]{12})\.[0-9]+`)
90+
goModMatch := goModRe.FindSubmatch(goModContent)
91+
require.NotNil(t, goModMatch, "failed to find buf.build/gen/go/redpandadata/core/protocolbuffers/go version in go.mod")
92+
goModCommit := string(goModMatch[1])
93+
94+
require.Equal(t, goModCommit, bufGenCommit,
95+
"buf.gen.yaml module version (%s) does not match go.mod dependency version (%s). "+
96+
"After updating the buf.build/gen/go/redpandadata/core/protocolbuffers/go dependency in go.mod, "+
97+
"update buf.gen.yaml module commit hash and run 'buf generate' from the repo root to regenerate proto comments.",
98+
bufGenCommit, goModCommit)
99+
}

0 commit comments

Comments
 (0)