Skip to content

Commit 40a2334

Browse files
Add logic to skip generation if protoc is missing or not the version we want
Helpful for local development
1 parent 0b325c7 commit 40a2334

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pb/gen.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
#!/bin/bash
22

33
# Run this script from its directory, so that badgerpb4.proto is where it's expected to
4-
# be.
4+
# be. Only run this script if you've made changes to the API in badgerpb4.proto.
5+
6+
# Check if protoc version matches expected version first
7+
EXPECTED_PROTOC_VERSION="3.21.12"
8+
ACTUAL_PROTOC_VERSION=$(protoc --version 2>/dev/null | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
9+
10+
if [[ ${ACTUAL_PROTOC_VERSION} != "${EXPECTED_PROTOC_VERSION}" ]]; then
11+
echo "Warning: protoc version mismatch"
12+
echo "Expected: ${EXPECTED_PROTOC_VERSION}"
13+
echo "Actual: ${ACTUAL_PROTOC_VERSION:-'not found'}"
14+
echo "Skipping generation"
15+
exit 0
16+
fi
517

618
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0
19+
20+
# Get the GOPATH and add the bin directory to PATH
21+
GOPATH=$(go env GOPATH)
22+
export PATH="${GOPATH}/bin:${PATH}"
23+
724
protoc --go_out=. --go_opt=paths=source_relative badgerpb4.proto

0 commit comments

Comments
 (0)