github.com/MetalBlockchain/metalgo@v1.11.9/scripts/protobuf_codegen.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -euo pipefail
     4  
     5  if ! [[ "$0" =~ scripts/protobuf_codegen.sh ]]; then
     6    echo "must be run from repository root"
     7    exit 255
     8  fi
     9  
    10  ## ensure the correct version of "buf" is installed
    11  BUF_VERSION='1.31.0'
    12  if [[ $(buf --version | cut -f2 -d' ') != "${BUF_VERSION}" ]]; then
    13    echo "could not find buf ${BUF_VERSION}, is it installed + in PATH?"
    14    exit 255
    15  fi
    16  
    17  ## install "protoc-gen-go"
    18  PROTOC_GEN_GO_VERSION='v1.33.0'
    19  go install -v google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION}
    20  if [[ $(protoc-gen-go --version | cut -f2 -d' ') != "${PROTOC_GEN_GO_VERSION}" ]]; then
    21    # e.g., protoc-gen-go v1.28.1
    22    echo "could not find protoc-gen-go ${PROTOC_GEN_GO_VERSION}, is it installed + in PATH?"
    23    exit 255
    24  fi
    25  
    26  ### install "protoc-gen-go-grpc"
    27  PROTOC_GEN_GO_GRPC_VERSION='1.3.0'
    28  go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc@v${PROTOC_GEN_GO_GRPC_VERSION}
    29  if [[ $(protoc-gen-go-grpc --version | cut -f2 -d' ') != "${PROTOC_GEN_GO_GRPC_VERSION}" ]]; then
    30    # e.g., protoc-gen-go-grpc 1.3.0
    31    echo "could not find protoc-gen-go-grpc ${PROTOC_GEN_GO_GRPC_VERSION}, is it installed + in PATH?"
    32    exit 255
    33  fi
    34  
    35  TARGET=$PWD/proto
    36  if [ -n "${1:-}" ]; then
    37    TARGET="$1"
    38  fi
    39  
    40  # move to api directory
    41  cd "$TARGET"
    42  
    43  echo "Running protobuf fmt..."
    44  buf format -w
    45  
    46  echo "Running protobuf lint check..."
    47  if ! buf lint;  then
    48      echo "ERROR: protobuf linter failed"
    49      exit 1
    50  fi
    51  
    52  echo "Re-generating protobuf..."
    53  if ! buf generate;  then
    54      echo "ERROR: protobuf generation failed"
    55      exit 1
    56  fi