diff --git a/Dockerfile b/Dockerfile index fa35848a..65cebd53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,6 +58,8 @@ RUN make -C /go/src/github.com/envoyproxy/protoc-gen-validate/ build RUN go get -u github.com/mwitkow/go-proto-validators/protoc-gen-govalidators +# Add Ruby Sorbet types support (rbi) +RUN go get -u github.com/coinbase/protoc-gen-rbi # Add scala support RUN curl -LO https://github.com/scalapb/ScalaPB/releases/download/v0.9.6/protoc-gen-scala-0.9.6-linux-x86_64.zip \ diff --git a/README.md b/README.md index 192c5784..f8c598e9 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,9 @@ $ docker run ... namely/protoc-all -f protorepo/catalog/catalog.proto -l go # which will generate files in a `protorepo` directory. ``` +### Ruby-specific options +`--with-rbi` to generate Ruby Sorbet type definition .rbi files + ## gRPC Gateway (Experimental) This repo also provides a docker images `namely/gen-grpc-gateway` that diff --git a/all/entrypoint.sh b/all/entrypoint.sh index 142b2993..abb505a3 100755 --- a/all/entrypoint.sh +++ b/all/entrypoint.sh @@ -15,6 +15,7 @@ printUsage() { echo " --lint CHECKS Enable linting protoc-lint (CHECKS are optional - see https://github.com/ckaznocha/protoc-gen-lint#optional-checks)" echo " --with-gateway Generate grpc-gateway files (experimental)." echo " --with-docs FORMAT Generate documentation (FORMAT is optional - see https://github.com/pseudomuto/protoc-gen-doc#invoking-the-plugin)" + echo " --with-rbi Generate Sorbet type declaration files (.rbi files) - see https://github.com/coinbase/protoc-gen-rbi" echo " --with-typescript Generate TypeScript declaration files (.d.ts files) - see https://github.com/improbable-eng/ts-protoc-gen#readme" echo " --with-validator Generate validations for (${VALIDATOR_SUPPORTED_LANGUAGES[@]}) - see https://github.com/envoyproxy/protoc-gen-validate" echo " --go-source-relative Make go import paths 'source_relative' - see https://github.com/golang/protobuf#parameters" @@ -37,6 +38,7 @@ GEN_DOCS=false GEN_VALIDATOR=false VALIDATOR_SUPPORTED_LANGUAGES=("go" "gogo" "cpp" "java" "python") DOCS_FORMAT="html,index.html" +GEN_RBI=false GEN_TYPESCRIPT=false LINT=false LINT_CHECKS="" @@ -109,6 +111,10 @@ while test $# -gt 0; do fi shift ;; + --with-rbi) + GEN_RBI=true + shift + ;; --with-typescript) GEN_TYPESCRIPT=true shift @@ -215,6 +221,11 @@ if [[ "$GO_VALIDATOR" == true && "$GEN_LANG" != "go" ]]; then exit 1 fi +if [[ "$GEN_RBI" == true && "$GEN_LANG" != "ruby" ]]; then + echo "Generating RBI declaration files is a Ruby specific option." + exit 1 +fi + if [[ "$GEN_TYPESCRIPT" == true && "$GEN_LANG" != "node" ]]; then echo "Generating TypeScript declaration files is Node specific." exit 1 @@ -315,6 +326,10 @@ if [[ $GEN_DOCS == true ]]; then GEN_STRING="$GEN_STRING --doc_opt=$DOCS_FORMAT --doc_out=$OUT_DIR/doc" fi +if [[ $GEN_RBI == true ]]; then + GEN_STRING="$GEN_STRING --rbi_out=$OUT_DIR" +fi + if [[ $GEN_TYPESCRIPT == true ]]; then GEN_STRING="$GEN_STRING --ts_out=service=grpc-node:$OUT_DIR" fi diff --git a/all/test.sh b/all/test.sh index af5c3a5e..7ccd9a4c 100755 --- a/all/test.sh +++ b/all/test.sh @@ -36,6 +36,14 @@ testGeneration() { current_path=$(dirname $current_path) done fi + if [[ "$extra_args" == *"--with-rbi"* ]]; then + # Test that we have generated the .d.ts files. + rbi_file_count=$(find $expected_output_dir -type f -name "*.rbi" | wc -l) + if [ $rbi_file_count -ne 2 ]; then + echo ".rbi files were not generated in $expected_output_dir" + exit 1 + fi + fi if [[ "$extra_args" == *"--with-typescript"* ]]; then # Test that we have generated the .d.ts files. ts_file_count=$(find $expected_output_dir -type f -name "*.d.ts" | wc -l) @@ -51,6 +59,9 @@ testGeneration() { # Test grpc-gateway generation (only valid for Go) testGeneration go "gen/pb-go" --with-gateway +# Test Sorbet RBI declaration file generation (only valid for Ruby) +testGeneration ruby "gen/pb-ruby" --with-rbi + # Test TypeScript declaration file generation (only valid for Node) testGeneration node "gen/pb-node" --with-typescript diff --git a/variables.sh b/variables.sh index 8d77a0f3..1beab1f5 100644 --- a/variables.sh +++ b/variables.sh @@ -4,7 +4,7 @@ DOCKER_REPO=${DOCKER_REPO} NAMESPACE=${NAMESPACE:-namely} GRPC_VERSION=${GRPC_VERSION:-1.28} GRPC_JAVA_VERSION=${GRPC_JAVA_VERSION:-1.28} -BUILD_VERSION=${BUILD_VERSION:-0} +BUILD_VERSION=${BUILD_VERSION:-1} CONTAINER=${DOCKER_REPO}${NAMESPACE} LATEST=${1:false} BUILDS=("protoc-all" "protoc" "prototool" "grpc-cli" "gen-grpc-gateway")