From 8f207855766d4e1928045413300fe18124e92d4a Mon Sep 17 00:00:00 2001 From: Edoardo Spadolini Date: Wed, 4 Sep 2024 20:26:55 +0200 Subject: [PATCH] Use buf.gen.yaml v2 (#46250) --- buf-connect-go.gen.yaml | 22 ++++++++++++++-------- buf-go.gen.yaml | 33 +++++++++++++++++++++++++-------- buf-gogo.gen.yaml | 17 +++++++++++++++-- buf-ts.gen.yaml | 26 +++++++++++++++++++++----- build.assets/genproto.sh | 36 +++++------------------------------- 5 files changed, 80 insertions(+), 54 deletions(-) diff --git a/buf-connect-go.gen.yaml b/buf-connect-go.gen.yaml index 399d328515176..646e871736820 100644 --- a/buf-connect-go.gen.yaml +++ b/buf-connect-go.gen.yaml @@ -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 diff --git a/buf-go.gen.yaml b/buf-go.gen.yaml index bf9082fe96034..e7b74255dd03e 100644 --- a/buf-go.gen.yaml +++ b/buf-go.gen.yaml @@ -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 diff --git a/buf-gogo.gen.yaml b/buf-gogo.gen.yaml index 65a70e364414d..37fad470a4ca7 100644 --- a/buf-gogo.gen.yaml +++ b/buf-gogo.gen.yaml @@ -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 diff --git a/buf-ts.gen.yaml b/buf-ts.gen.yaml index 15d6012ab3607..4aa16502181b4 100644 --- a/buf-ts.gen.yaml +++ b/buf-ts.gen.yaml @@ -1,13 +1,29 @@ -version: v1 +version: v2 + +inputs: + - directory: . + paths: + - api/proto/teleport/accesslist/ + - 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/plugin@2.9.3 - -- - 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 diff --git a/build.assets/genproto.sh b/build.assets/genproto.sh index 4dd4a8aa8d1b2..7e7e3fe733094 100755 --- a/build.assets/genproto.sh +++ b/build.assets/genproto.sh @@ -42,44 +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/userpreferences/ \ - --path=api/proto/teleport/accesslist/ \ - --path=api/proto/teleport/trait/ \ - --path=api/proto/teleport/header/ + [[ $skip_js -eq 0 ]] && echoed buf generate --template=buf-ts.gen.yaml } main "$@"