Skip to content

Commit

Permalink
Add support for Ruby Sorbet RBI typedef generation (#171)
Browse files Browse the repository at this point in the history
* Add support for Ruby Sorbet RBI typedef generation

* Bump build version

* Rerun CI (empty commit)

Co-authored-by: James Shkolnik <[email protected]>
  • Loading branch information
shkolnik and shkolnik authored Mar 18, 2020
1 parent 7d5fe20 commit 657a4d7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions all/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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=""
Expand Down Expand Up @@ -109,6 +111,10 @@ while test $# -gt 0; do
fi
shift
;;
--with-rbi)
GEN_RBI=true
shift
;;
--with-typescript)
GEN_TYPESCRIPT=true
shift
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions all/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 657a4d7

Please sign in to comment.