Browse Source

make+travis: verify compiled protos on travis

master
Conner Fromknecht 5 years ago committed by Oliver Gugger
parent
commit
7a1013fb9e
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
  1. 22
      .travis.yml
  2. 10
      Makefile
  3. 7
      lnrpc/.clang-format
  4. 72
      scripts/install_travis_proto.sh

22
.travis.yml

@ -2,11 +2,14 @@ language: go
cache:
directories:
- ~/bitcoin/bitcoin-0.19.0.1/bin
- $DOWNLOAD_CACHE
- $GOCACHE
- $GOPATH/pkg/mod
- $GOPATH/src/github.com/btcsuite
- $GOPATH/src/github.com/golang
- $GOPATH/src/github.com/grpc-ecosystem
- $GOPATH/src/gopkg.in/alecthomas
- $GOPATH/src/google.golang.org
# Remove Travis' default flag --depth=50 from the git clone command to make sure
# we have the whole git history, including the commit we lint against.
@ -19,18 +22,27 @@ go:
env:
global:
- GOCACHE=$HOME/.go-build
- DOWNLOAD_CACHE=$HOME/download_cache
sudo: required
before_script: bash ./scripts/install_bitcoind.sh
addons:
apt:
packages:
- clang-format
before_script:
- bash ./scripts/install_travis_proto.sh
- bash ./scripts/install_bitcoind.sh
jobs:
include:
- stage: Build
script:
- make unit pkg=... case=_NONE_
- make lint
- make btcd
script:
- make rpc-check
- make unit pkg=... case=_NONE_
- make lint
- make btcd
- stage: Test
script: make travis-cover
name: Unit Cover

10
Makefile

@ -174,6 +174,14 @@ rpc:
@$(call print, "Compiling protos.")
cd ./lnrpc; ./gen_protos.sh
rpc-format:
@$(call print, "Formatting protos.")
cd ./lnrpc; find . -name "*.proto" | xargs clang-format --style=file -i
rpc-check: rpc-format rpc
@$(call print, "Verifying protos.")
if test -n "$$(git describe --dirty | grep dirty)"; then echo "Protos not properly formatted or not compiled with v3.4.0"; git status; git diff; exit 1; fi
mobile-rpc:
@$(call print, "Creating mobile RPC from protos.")
cd ./mobile; ./gen_bindings.sh
@ -223,6 +231,8 @@ clean:
lint \
list \
rpc \
rpc-format \
rpc-check \
mobile-rpc \
vendor \
ios \

7
lnrpc/.clang-format

@ -0,0 +1,7 @@
---
Language: Proto
BasedOnStyle: Google
IndentWidth: 4
AllowShortFunctionsOnASingleLine: None
SpaceBeforeParens: Always
CompactNamespaces: false

72
scripts/install_travis_proto.sh

@ -0,0 +1,72 @@
#!/usr/bin/env bash
# Abort on error (-e) and print commands (-v).
set -ev
# See README.md in lnrpc why we need these specific versions/commits.
PROTOC_VERSION=3.4.0
PROTOBUF_VERSION="b5d812f8a3706043e23a9cd5babf2e5423744d30"
GENPROTO_VERSION="a8101f21cf983e773d0c1133ebc5424792003214"
GRPC_GATEWAY_VERSION="v1.8.6"
# This script is specific to Travis CI so we only need to support linux x64.
PROTOC_URL="https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip"
PROTOC_DL_CACHE_DIR="${DOWNLOAD_CACHE:-/tmp/download_cache}/protoc"
# install_protoc copies the cached protoc binary to the $PATH or downloads it
# if no cached version is found.
install_protoc() {
if [ -f "${PROTOC_DL_CACHE_DIR}/bin/protoc" ]; then
echo "Using cached version of protoc"
else
wget -O /tmp/protoc.zip $PROTOC_URL
mkdir -p "${PROTOC_DL_CACHE_DIR}"
unzip -o /tmp/protoc.zip -d "${PROTOC_DL_CACHE_DIR}"
chmod -R a+rx "${PROTOC_DL_CACHE_DIR}/"
fi
sudo cp "${PROTOC_DL_CACHE_DIR}/bin/protoc" /usr/local/bin
sudo cp -r "${PROTOC_DL_CACHE_DIR}/include" /usr/local
}
# install_protobuf downloads and compiles the Golang protobuf library that
# encodes/decodes all protobuf messages from/to Go structs.
install_protobuf() {
local install_path="$GOPATH/src/github.com/golang/protobuf"
if [ ! -d "$install_path" ]; then
git clone https://github.com/golang/protobuf "$install_path"
fi
pushd "$install_path"
git reset --hard $PROTOBUF_VERSION
make
popd
}
# install_genproto downloads the Golang protobuf generator that converts the
# .proto files into Go interface stubs.
install_genproto() {
local install_path="$GOPATH/src/google.golang.org/genproto"
if [ ! -d "$install_path" ]; then
git clone https://github.com/google/go-genproto "$install_path"
fi
pushd "$install_path"
git reset --hard $GENPROTO_VERSION
popd
}
# install_grpc_gateway downloads and installs the gRPC gateway that converts
# .proto files into REST gateway code.
install_grpc_gateway() {
local install_path="$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway"
if [ ! -d "$install_path" ]; then
git clone https://github.com/grpc-ecosystem/grpc-gateway "$install_path"
fi
pushd "$install_path"
git reset --hard $GRPC_GATEWAY_VERSION
GO111MODULE=on go install ./protoc-gen-grpc-gateway ./protoc-gen-swagger
popd
}
install_protoc
install_protobuf
install_genproto
install_grpc_gateway
Loading…
Cancel
Save