Skip to content

Commit 130ffe5

Browse files
authored
Merge pull request #29101 from r-vasquez/import-from-buf
[UX-450] buf/rpk: import from BSR and not files for rpk comments
2 parents e0bcae7 + f3355f0 commit 130ffe5

File tree

8 files changed

+94
-15
lines changed

8 files changed

+94
-15
lines changed

.github/workflows/rpk-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ jobs:
7474
with:
7575
setup_only: true
7676
- name: Generate proto files
77-
run: buf generate --path proto/redpanda/core/admin/v2/shadow_link.proto --path proto/redpanda/core/common/v1/acl.proto --path proto/redpanda/core/common/v1/tls.proto
77+
run: buf generate
7878
- name: Check for uncommitted changes
7979
run: |
8080
if ! git diff --exit-code src/go/rpk/gen/; then
8181
git diff src/go/rpk/gen/
8282
echo "Error: Generated proto files are out of date"
83-
echo "Run 'buf generate --path proto/redpanda/core/admin/v2/shadow_link.proto --path proto/redpanda/core/common/v1/acl.proto --path proto/redpanda/core/common/v1/tls.proto' and commit the changes"
83+
echo "Run 'buf generate' and commit the changes"
8484
exit 1
8585
fi

BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,11 @@ filegroup(
6363
srcs = ["ubsan_suppressions.txt"],
6464
visibility = ["//visibility:public"],
6565
)
66+
67+
exports_files(
68+
[
69+
"MODULE.bazel",
70+
"buf.gen.yaml",
71+
],
72+
visibility = ["//visibility:public"],
73+
)

buf.gen.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
version: v2
22
managed:
33
enabled: false
4+
inputs:
5+
- module: buf.build/redpandadata/core:19149a4a2435
6+
paths:
7+
- redpanda/core/admin/v2/shadow_link.proto
8+
- redpanda/core/common/v1/acl.proto
9+
- redpanda/core/common/v1/tls.proto
410
plugins:
511
# Custom comment extraction plugin - we ONLY generate comments related files,
612
# The rest comes from buf.build/gen/go/redpandadata/core/protocolbuffers/go
713
- local: tools/go-comment-pbgen/run-plugin.sh
814
out: .
915
opt:
1016
- paths=import
11-
- Mproto/redpanda/core/admin/v2/shadow_link.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/admin/v2
12-
- Mproto/redpanda/core/admin/v2/broker.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/admin/v2
13-
- Mproto/redpanda/core/admin/v2/cluster.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/admin/v2
14-
- Mproto/redpanda/core/admin/v2/kafka_connections.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/admin/v2
15-
- Mproto/redpanda/core/common/v1/acl.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/common/v1
16-
- Mproto/redpanda/core/common/v1/ntp.proto=github.com/redpanda-data/redpanda/src/go/rpk/gen/protocomments/common/v1
17-
- 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/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
exports_files(
2+
["go.mod"],
3+
visibility = ["//visibility:public"],
4+
)

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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ buf.build/gen/go/redpandadata/common/protocolbuffers/go v1.36.10-20251106193941-
1010
buf.build/gen/go/redpandadata/common/protocolbuffers/go v1.36.10-20251106193941-bb850a944663.1/go.mod h1:EhA16a3hhvTg9rzQ69ch2mJ2ppasEGJFy8ViCc8PYUE=
1111
buf.build/gen/go/redpandadata/core/connectrpc/go v1.19.1-20251125205739-05aa34b3829a.2 h1:gVJAyaNRisvoR2bgYxTLZorChyitt+gpx/FSdP0y2Og=
1212
buf.build/gen/go/redpandadata/core/connectrpc/go v1.19.1-20251125205739-05aa34b3829a.2/go.mod h1:/y8qVz8QQFux6oxVWxu+KeC73QYqygF0wXZEIvaQU5k=
13-
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.10-20251204205609-c0c7c0a68f89.1 h1:Ya1VBu8W/qJV6ROMI4z5r1gwWDtAQaZavSe6o1o+IQk=
14-
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.10-20251204205609-c0c7c0a68f89.1/go.mod h1:QenSPzqxZpyo9hHIpRzTetvDchelVDzimnmaggHKenc=
13+
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.11-20251218215858-19149a4a2435.1 h1:LLKPTO8tKmB4nIB2WlMWavkVhRV0rWwXluy6mJfdqUM=
14+
buf.build/gen/go/redpandadata/core/protocolbuffers/go v1.36.11-20251218215858-19149a4a2435.1/go.mod h1:5sjUVquVwNxt3Q/EhE/UW0BBJ5sgPiaVTw8//wxRULI=
1515
buf.build/gen/go/redpandadata/dataplane/connectrpc/go v1.19.1-20251209134521-106822fddcf0.2 h1:mCwJEx9wqHwQZscE0vuW3szVb5QjlStjae5dr+gx1Lo=
1616
buf.build/gen/go/redpandadata/dataplane/connectrpc/go v1.19.1-20251209134521-106822fddcf0.2/go.mod h1:AUXVi3l4mOkfox1XUVw2U0OdvAK85qPS58RcuLnr7uM=
1717
buf.build/gen/go/redpandadata/dataplane/protocolbuffers/go v1.36.10-20251209134521-106822fddcf0.1 h1:xjIO92l2DoT4BRdNeTOH30M+zJGCDY+sYK+t6anhfIk=
@@ -456,8 +456,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20251029180050-ab9386a59fda h1:
456456
google.golang.org/genproto/googleapis/rpc v0.0.0-20251029180050-ab9386a59fda/go.mod h1:7i2o+ce6H/6BluujYR+kqX3GKH+dChPTQU19wjRPiGk=
457457
google.golang.org/grpc v1.73.0 h1:VIWSmpI2MegBtTuFt5/JWy2oXxtjJ/e89Z70ImfD2ok=
458458
google.golang.org/grpc v1.73.0/go.mod h1:50sbHOUqWoCQGI8V2HQLJM0B+LMlIUjNSZmow7EVBQc=
459-
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
460-
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
459+
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
460+
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
461461
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
462462
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
463463
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

src/go/rpk/pkg/cli/shadow/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ go_test(
5757
"types_test.go",
5858
"update_test.go",
5959
],
60+
data = [
61+
"//:MODULE.bazel",
62+
"//:buf.gen.yaml",
63+
"//src/go/rpk:go.mod",
64+
],
6065
embed = [":shadow"],
6166
deps = [
6267
"@build_buf_gen_go_redpandadata_cloud_protocolbuffers_go//redpanda/api/controlplane/v1:controlplane",

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"
1316
"testing"
1417

1518
"github.com/stretchr/testify/require"
1619
)
1720

21+
// findRedpandaRepoRoot searches upward for the *Redpanda* repository root by
22+
// looking for the MODULE.bazel file.
23+
func findRedpandaRepoRoot(t *testing.T) string {
24+
// Try from current working directory first. It has to be found from WD to
25+
// work with Bazel tests.
26+
dir, err := os.Getwd()
27+
require.NoError(t, err)
28+
for {
29+
if _, err := os.Stat(filepath.Join(dir, "MODULE.bazel")); err == nil {
30+
return dir
31+
}
32+
parent := filepath.Dir(dir)
33+
if parent == dir {
34+
t.Fatal("failed to find repo root (MODULE.bazel file)")
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)