Skip to content

Commit

Permalink
Use buf.gen.yaml v2 (#46247)
Browse files Browse the repository at this point in the history
  • Loading branch information
espadolini authored Sep 4, 2024
1 parent acc08a3 commit 6205e30
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 55 deletions.
22 changes: 14 additions & 8 deletions buf-connect-go.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
version: v1
version: v2

inputs:
- directory: .
paths:
- proto/prehog/

managed:
enabled: true
go_package_prefix:
default: github.com/gravitational/teleport/gen/proto/go
override:
- file_option: go_package_prefix
value: github.com/gravitational/teleport/gen/proto/go

plugins:
- name: go
strategy: all
path:
- local:
- go
- run
- google.golang.org/protobuf/cmd/protoc-gen-go
out: .
opt: module=github.com/gravitational/teleport
- name: connect-go
strategy: all
path:
- local:
- go
- run
- connectrpc.com/connect/cmd/protoc-gen-connect-go
out: .
opt: module=github.com/gravitational/teleport
strategy: all
33 changes: 25 additions & 8 deletions buf-go.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
version: v1
version: v2

inputs:
- directory: .
exclude_paths:
# generated by buf-gogo.gen.yaml
- api/proto/teleport/attestation/
- api/proto/teleport/legacy/
- api/proto/teleport/mfa/
- api/proto/teleport/usageevents/
- proto/teleport/lib/web/terminal/envelope.proto
# generated by buf-connect-go.gen.yaml
- proto/prehog/
- directory: .
paths:
# excluded by buf-gogo.gen.yaml
- api/proto/teleport/legacy/client/proto/event.proto

plugins:
- name: go
strategy: all
path:
- local:
- go
- run
- google.golang.org/protobuf/cmd/protoc-gen-go
out: .
opt:
- module=github.com/gravitational/teleport
# needed by teleport/lib/teleterm/v1/usage_events.proto
# needed by teleport/lib/teleterm/v1/usage_events.proto because we use
# managed mode for the go package name there
- Mprehog/v1alpha/connect.proto=github.com/gravitational/teleport/gen/proto/go/prehog/v1alpha;prehogv1alpha
- name: go-grpc
strategy: all
path:
- local:
- go
- run
- google.golang.org/grpc/cmd/protoc-gen-go-grpc
out: .
opt:
- module=github.com/gravitational/teleport
# needed by teleport/lib/teleterm/v1/usage_events.proto
# needed by teleport/lib/teleterm/v1/usage_events.proto because we use
# managed mode for the go package name there
- Mprehog/v1alpha/connect.proto=github.com/gravitational/teleport/gen/proto/go/prehog/v1alpha;prehogv1alpha
strategy: all
17 changes: 15 additions & 2 deletions buf-gogo.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
version: v1
version: v2

inputs:
- directory: .
paths:
- api/proto/teleport/attestation/
- api/proto/teleport/legacy/
- api/proto/teleport/mfa/
- api/proto/teleport/usageevents/
- proto/teleport/lib/web/terminal/envelope.proto
exclude_paths:
# generated by buf-go.gen.yaml
- api/proto/teleport/legacy/client/proto/event.proto

plugins:
- name: gogofast
- local: protoc-gen-gogofast
out: ./gogogen
opt:
- Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types
Expand Down
27 changes: 22 additions & 5 deletions buf-ts.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
version: v1
version: v2

inputs:
- directory: .
paths:
- api/proto/teleport/accesslist/
- api/proto/teleport/devicetrust/
- api/proto/teleport/header/
- api/proto/teleport/trait/
- api/proto/teleport/userpreferences/
- proto/prehog/
- proto/teleport/lib/teleterm/

plugins:
- name: typescript
out: gen/proto/ts
opt: eslint_disable,add_pb_suffix,server_grpc1,ts_nocheck
path:
- local:
- npm
- exec
- --yes
- --package=@protobuf-ts/[email protected]
- --
- protoc-gen-ts
out: gen/proto/ts
opt:
# the next time we tweak the ts codegen we should put the options in
# alphabetical order
- eslint_disable
- add_pb_suffix
- server_grpc1
- ts_nocheck
strategy: all
37 changes: 5 additions & 32 deletions build.assets/genproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,45 +42,18 @@ main() {
# this for us (and which is what we use for the non-gogo protogen).
rm -fr gogogen
trap 'rm -fr gogogen' EXIT # don't leave files behind
echoed buf generate --template=buf-gogo.gen.yaml \
--path=api/proto/teleport/legacy/ \
--path=api/proto/teleport/attestation/ \
--path=api/proto/teleport/usageevents/ \
--path=api/proto/teleport/mfa/ \
--path=proto/teleport/lib/web/terminal/envelope.proto \
--exclude-path=api/proto/teleport/legacy/client/proto/event.proto
echoed buf generate --template=buf-gogo.gen.yaml
cp -r gogogen/github.com/gravitational/teleport/. .
# error out if there's anything outside of github.com/gravitational/teleport
rm -fr gogogen/github.com/gravitational/teleport
rmdir gogogen/github.com/gravitational gogogen/github.com gogogen

# Generate protoc-gen-go protos (preferred).
echoed buf generate --template=buf-go.gen.yaml \
--exclude-path=api/proto/teleport/legacy/ \
--exclude-path=api/proto/teleport/attestation/ \
--exclude-path=api/proto/teleport/usageevents/ \
--exclude-path=api/proto/teleport/mfa/ \
--exclude-path=proto/teleport/lib/web/terminal/envelope.proto \
--exclude-path=proto/prehog/

# Generate event.proto separately because we only want to run it on this
# one particular file in legacy.
echoed buf generate --template=buf-go.gen.yaml \
--path=api/proto/teleport/legacy/client/proto/event.proto

# Generate connect-go protos.
echoed buf generate --template=buf-connect-go.gen.yaml \
--path=proto/prehog/
# Generate go, go-grpc and connect-go protos (preferred).
echoed buf generate --template=buf-go.gen.yaml
echoed buf generate --template=buf-connect-go.gen.yaml

# Generate TS protos.
[[ $skip_js -eq 0 ]] && echoed buf generate --template=buf-ts.gen.yaml \
--path=proto/prehog/ \
--path=proto/teleport/lib/teleterm/ \
--path=api/proto/teleport/accesslist/ \
--path=api/proto/teleport/devicetrust/ \
--path=api/proto/teleport/header/ \
--path=api/proto/teleport/trait/ \
--path=api/proto/teleport/userpreferences/
[[ $skip_js -eq 0 ]] && echoed buf generate --template=buf-ts.gen.yaml
}

main "$@"

0 comments on commit 6205e30

Please sign in to comment.