Skip to content

Commit

Permalink
Add go:generate directive for protobuf (#11997)
Browse files Browse the repository at this point in the history
* Add go:generate directive for protobuf

* Add protoc to Makefile

* Add protoc binary

* Attempt install protoc-gen-go-wsrpc

* w

* w

* w

* executable

* Update versions
  • Loading branch information
samsondav authored Feb 13, 2024
1 parent c89a15a commit ce84ce5
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ jobs:
uses: ./.github/actions/setup-go
with:
only-modules: "true"
- name: Install protoc-gen-go-wsrpc
run: curl https://github.com/smartcontractkit/wsrpc/raw/main/cmd/protoc-gen-go-wsrpc/protoc-gen-go-wsrpc --output $HOME/go/bin/protoc-gen-go-wsrpc && chmod +x $HOME/go/bin/protoc-gen-go-wsrpc
- name: Setup NodeJS
uses: ./.github/actions/setup-nodejs
- run: make generate # generate install go deps
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ postgres 13.3
helm 3.10.3
zig 0.10.1
golangci-lint 1.55.2
protoc 23.2
protoc 25.1
7 changes: 6 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ abigen: ## Build & install abigen.
./tools/bin/build_abigen

.PHONY: generate
generate: abigen codecgen mockery ## Execute all go:generate commands.
generate: abigen codecgen mockery protoc ## Execute all go:generate commands.
go generate -x ./...

.PHONY: testscripts
Expand Down Expand Up @@ -124,6 +124,11 @@ mockery: $(mockery) ## Install mockery.
codecgen: $(codecgen) ## Install codecgen
go install github.com/ugorji/go/codec/[email protected]

.PHONY: protoc
protoc: ## Install protoc
core/scripts/install-protoc.sh 25.1 /
go install google.golang.org/protobuf/cmd/protoc-gen-go@`go list -m -json google.golang.org/protobuf | jq -r .Version`

.PHONY: telemetry-protobuf
telemetry-protobuf: $(telemetry-protobuf) ## Generate telemetry protocol buffers.
protoc \
Expand Down
54 changes: 54 additions & 0 deletions core/scripts/install-protoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -x


VERSION=$1

if [ "$VERSION" == "" ]; then
echo "version required"
exit 1
fi

os=$(uname)
arch=$(uname -m)

install_dir=$HOME/.local
$install_dir/bin/protoc --version | grep $VERSION
rc=$?
if [ $rc -eq 0 ]; then
# we have the current VERSION
echo "protoc up-to-date @ $VERSION"
exit 0
fi


if [ "$os" == "Linux" ] ; then
os="linux"
if [$arch != "x86_64"]; then
echo "unsupported os $os-$arch update $0"
exit 1
fi
elif [ "$os" == "Darwin" ] ; then
os="osx"
# make life simply and download the universal binary
arch="universal_binary"
else
echo "unsupported os $os. update $0"
exit 1
fi

workdir=$(mktemp -d)
pushd $workdir
pb_url="https://github.com/protocolbuffers/protobuf/releases"
artifact=protoc-$VERSION-$os-$arch.zip
curl -LO $pb_url/download/v${VERSION}/$artifact
if [[ ! -d $install_dir ]]; then
mkdir $install_dir
fi
unzip -uo $artifact -d $install_dir
rm $artifact

echo "protoc $VERSION installed in $install_dir"
echo "Add $install_dir/bin to PATH"
export PATH=$install_dir/bin:$PATH
popd
2 changes: 2 additions & 0 deletions core/services/relay/evm/mercury/wsrpc/pb/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-wsrpc_out=. --go-wsrpc_opt=paths=source_relative mercury.proto
package pb
2 changes: 1 addition & 1 deletion core/services/relay/evm/mercury/wsrpc/pb/mercury.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ce84ce5

Please sign in to comment.