grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.56k stars 762 forks source link

/usr/local/bin/protoc-gen-grpc-web: 1: Syntax error: redirection unexpected when generating the grpc-web code on Github Actions #1169

Closed LanDinh closed 2 years ago

LanDinh commented 2 years ago

Hi all,

As is good practice, I don't check in generated code. This means that my CI (Github Actions) needs to generate the protobuf code first before running my tests. I install both protoc and protoc-gen-grpc-web as follows:

sudo apt-get update && sudo apt-get install protobuf-compiler --yes
curl -o /usr/local/bin/protoc-gen-grpc-web https://github.com/grpc/grpc-web/releases/download/1.3.0/protoc-gen-grpc-web-1.3.0-linux-x86_64
chmod +x /usr/local/bin/protoc-gen-grpc-web

I call protoc like this:

protoc -I="${proto_in}" --js_out=import_style=commonjs:"${typescript_out}" --grpc-web_out=import_style=commonjs+dts,mode=grpcweb:"${typescript_out}" "${proto_in}"/*.proto

And it logs the following error:

/usr/local/bin/protoc-gen-grpc-web: 1: Syntax error: redirection unexpected

This workflow runs on ubuntu-latest via the Github hosted Action runners.

The script that does the call to generate the protos is marked as executable and is called directly and contains the shebang #!/bin/bash, so it should run within bash as shell.

This means that since I added the proto generation, my CI is failing - can you help me? :D

lukasmoellerch commented 2 years ago

I'd assume that the issue is that https://github.com/grpc/grpc-web/releases/download/1.3.0/protoc-gen-grpc-web-1.3.0-linux-x86_64 is a redirect to a https://github-releases.githubusercontent.com/ url. Thus you might be downloading the HTML content instead of the actual binary - thus the file won't work as an executable. Can you add the -L flag which results in curl following redirects? (I only tried this on Debian so far)

LanDinh commented 2 years ago

This was exactly it. Thanks for your help!