Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | if [[ `uname -a` = *"Darwin"* ]]; then |
| 4 | echo "It seems you are running on Mac. This script does not work on Mac. See https://github.com/grpc/grpc-go/issues/2047" |
| 5 | exit 1 |
| 6 | fi |
| 7 | |
| 8 | set -ex # Exit on error; debugging enabled. |
| 9 | set -o pipefail # Fail a pipe if any sub-command fails. |
| 10 | |
| 11 | die() { |
| 12 | echo "$@" >&2 |
| 13 | exit 1 |
| 14 | } |
| 15 | |
| 16 | PATH="$GOPATH/bin:$GOROOT/bin:$PATH" |
| 17 | |
| 18 | # Check proto in manual runs or cron runs. |
| 19 | if [[ "$TRAVIS" != "true" || "$TRAVIS_EVENT_TYPE" = "cron" ]]; then |
| 20 | check_proto="true" |
| 21 | fi |
| 22 | |
| 23 | if [ "$1" = "-install" ]; then |
| 24 | go get -d \ |
| 25 | google.golang.org/grpc/... |
| 26 | go get -u \ |
| 27 | github.com/golang/lint/golint \ |
| 28 | golang.org/x/tools/cmd/goimports \ |
| 29 | honnef.co/go/tools/cmd/staticcheck \ |
| 30 | github.com/client9/misspell/cmd/misspell \ |
| 31 | github.com/golang/protobuf/protoc-gen-go |
| 32 | if [[ "$check_proto" = "true" ]]; then |
| 33 | if [[ "$TRAVIS" = "true" ]]; then |
| 34 | PROTOBUF_VERSION=3.3.0 |
| 35 | PROTOC_FILENAME=protoc-${PROTOBUF_VERSION}-linux-x86_64.zip |
| 36 | pushd /home/travis |
| 37 | wget https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/${PROTOC_FILENAME} |
| 38 | unzip ${PROTOC_FILENAME} |
| 39 | bin/protoc --version |
| 40 | popd |
| 41 | elif ! which protoc > /dev/null; then |
| 42 | die "Please install protoc into your path" |
| 43 | fi |
| 44 | fi |
| 45 | exit 0 |
| 46 | elif [[ "$#" -ne 0 ]]; then |
| 47 | die "Unknown argument(s): $*" |
| 48 | fi |
| 49 | |
| 50 | # TODO: Remove this check and the mangling below once "context" is imported |
| 51 | # directly. |
| 52 | if git status --porcelain | read; then |
| 53 | die "Uncommitted or untracked files found; commit changes first" |
| 54 | fi |
| 55 | |
| 56 | git ls-files "*.go" | xargs grep -L "\(Copyright [0-9]\{4,\} gRPC authors\)\|DO NOT EDIT" 2>&1 | tee /dev/stderr | (! read) |
| 57 | git ls-files "*.go" | xargs grep -l '"unsafe"' 2>&1 | (! grep -v '_test.go') | tee /dev/stderr | (! read) |
| 58 | git ls-files "*.go" | xargs grep -l '"math/rand"' 2>&1 | (! grep -v '^examples\|^stress\|grpcrand') | tee /dev/stderr | (! read) |
| 59 | gofmt -s -d -l . 2>&1 | tee /dev/stderr | (! read) |
| 60 | goimports -l . 2>&1 | tee /dev/stderr | (! read) |
| 61 | golint ./... 2>&1 | (grep -vE "(_mock|\.pb)\.go:" || true) | tee /dev/stderr | (! read) |
| 62 | |
| 63 | # Undo any edits made by this script. |
| 64 | cleanup() { |
| 65 | git reset --hard HEAD |
| 66 | } |
| 67 | trap cleanup EXIT |
| 68 | |
| 69 | # Rewrite golang.org/x/net/context -> context imports (see grpc/grpc-go#1484). |
| 70 | # TODO: Remove this mangling once "context" is imported directly (grpc/grpc-go#711). |
| 71 | git ls-files "*.go" | xargs sed -i 's:"golang.org/x/net/context":"context":' |
| 72 | set +o pipefail |
| 73 | # TODO: Stop filtering pb.go files once golang/protobuf#214 is fixed. |
| 74 | go tool vet -all . 2>&1 | grep -vE '(clientconn|transport\/transport_test).go:.*cancel (function|var)' | grep -vF '.pb.go:' | tee /dev/stderr | (! read) |
| 75 | set -o pipefail |
| 76 | git reset --hard HEAD |
| 77 | |
| 78 | if [[ "$check_proto" = "true" ]]; then |
| 79 | PATH="/home/travis/bin:$PATH" make proto && \ |
| 80 | git status --porcelain 2>&1 | (! read) || \ |
| 81 | (git status; git --no-pager diff; exit 1) |
| 82 | fi |
| 83 | |
| 84 | # TODO(menghanl): fix errors in transport_test. |
| 85 | staticcheck -ignore ' |
| 86 | google.golang.org/grpc/transport/transport_test.go:SA2002 |
| 87 | google.golang.org/grpc/benchmark/benchmain/main.go:SA1019 |
| 88 | google.golang.org/grpc/stats/stats_test.go:SA1019 |
| 89 | google.golang.org/grpc/test/end2end_test.go:SA1019 |
| 90 | google.golang.org/grpc/balancer_test.go:SA1019 |
| 91 | google.golang.org/grpc/balancer.go:SA1019 |
| 92 | google.golang.org/grpc/clientconn_test.go:SA1019 |
| 93 | ' ./... |
| 94 | misspell -error . |