1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-26 13:48:53 +08:00

NOISSUE - Fix CI (#1204)

Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
This commit is contained in:
Dušan Borovčanin 2020-06-05 17:29:24 +02:00 committed by GitHub
parent 340e685d70
commit a1643b1e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,101 +9,105 @@ GRPC_VERSION=v1.29.1
function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; } function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
update_go() { update_go() {
CURRENT_GO_VERSION=$(go version | sed 's/[^0-9.]*\([0-9.]*\).*/\1/') CURRENT_GO_VERSION=$(go version | sed 's/[^0-9.]*\([0-9.]*\).*/\1/')
if version_gt $GO_VERSION $CURRENT_GO_VERSION; then if version_gt $GO_VERSION $CURRENT_GO_VERSION; then
echo "Update go version from $CURRENT_GO_VERSION to $GO_VERSION ..." echo "Update go version from $CURRENT_GO_VERSION to $GO_VERSION ..."
sudo rm -rf /usr/local/go sudo rm -rf /usr/local/go
sudo rm -rf /usr/local/golang sudo rm -rf /usr/local/golang
sudo rm -rf /usr/bin/go sudo rm -rf /usr/bin/go
wget https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz wget https://dl.google.com/go/go$GO_VERSION.linux-amd64.tar.gz
tar -xvf go$GO_VERSION.linux-amd64.tar.gz tar -xvf go$GO_VERSION.linux-amd64.tar.gz
rm go$GO_VERSION.linux-amd64.tar.gz rm go$GO_VERSION.linux-amd64.tar.gz
sudo mv go /usr/local sudo mv go /usr/local
export GOROOT=/usr/local/go export GOROOT=/usr/local/go
export GOPATH=/home/runner/go/src export GOPATH=/home/runner/go/src
export GOBIN=/home/runner/go/bin export GOBIN=/home/runner/go/bin
mkdir -p $GOPATH mkdir -p $GOPATH
mkdir $GOBIN mkdir $GOBIN
# remove other Go version from path # remove other Go version from path
export PATH=$PATH:/usr/local/go/bin:$GOBIN export PATH=$PATH:/usr/local/go/bin:$GOBIN
fi fi
go version go version
} }
setup_protoc() { setup_protoc() {
echo "Setting up protoc..." # Execute `go get` for protoc dependencies outside of project dir.
PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip cd ..
curl -0L https://github.com/google/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP -o $PROTOC_ZIP export GO111MODULE=on
unzip -o $PROTOC_ZIP -d protoc3 echo "Setting up protoc..."
sudo mv protoc3/bin/* /usr/local/bin/ PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip
sudo mv protoc3/include/* /usr/local/include/ curl -0L https://github.com/google/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP -o $PROTOC_ZIP
rm -f PROTOC_ZIP unzip -o $PROTOC_ZIP -d protoc3
sudo mv protoc3/bin/* /usr/local/bin/
sudo mv protoc3/include/* /usr/local/include/
rm -f PROTOC_ZIP
go get -u github.com/golang/protobuf/protoc-gen-go@$PROTOC_GEN_VERSION \ go get -u github.com/golang/protobuf/protoc-gen-go@$PROTOC_GEN_VERSION \
github.com/gogo/protobuf/protoc-gen-gofast@$PROTOC_GOFAST_VERSION \ github.com/gogo/protobuf/protoc-gen-gofast@$PROTOC_GOFAST_VERSION \
google.golang.org/grpc@$GRPC_VERSION google.golang.org/grpc@$GRPC_VERSION
export PATH=$PATH:/usr/local/bin/protoc export PATH=$PATH:/usr/local/bin/protoc
cd mainflux
} }
setup_mf() { setup_mf() {
echo "Setting up Mainflux..." echo "Setting up Mainflux..."
for p in $(ls *.pb.go); do for p in $(ls *.pb.go); do
mv $p $p.tmp mv $p $p.tmp
done done
for p in $(ls pkg/*/*.pb.go); do for p in $(ls pkg/*/*.pb.go); do
mv $p $p.tmp mv $p $p.tmp
done done
make proto make proto
for p in $(ls *.pb.go); do for p in $(ls *.pb.go); do
if ! cmp -s $p $p.tmp; then if ! cmp -s $p $p.tmp; then
echo "Proto file and generated Go file $p are out of sync!" echo "Proto file and generated Go file $p are out of sync!"
exit 1 exit 1
fi fi
done done
for p in $(ls pkg/*/*.pb.go); do for p in $(ls pkg/*/*.pb.go); do
if ! cmp -s $p $p.tmp; then if ! cmp -s $p $p.tmp; then
echo "Proto file and generated Go file $p are out of sync!" echo "Proto file and generated Go file $p are out of sync!"
exit 1 exit 1
fi fi
done done
make -j$NPROC make -j$NPROC
} }
setup_lint() { setup_lint() {
# binary will be $(go env GOBIN)/golangci-lint # binary will be $(go env GOBIN)/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOBIN) v1.24.0 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOBIN) v1.24.0
} }
setup() { setup() {
echo "Setting up..." echo "Setting up..."
update_go update_go
setup_protoc setup_protoc
setup_mf setup_mf
setup_lint setup_lint
} }
run_test() { run_test() {
echo "Running lint..." echo "Running lint..."
golangci-lint run --no-config --disable-all --enable=golint golangci-lint run --no-config --disable-all --enable=golint
echo "Running tests..." echo "Running tests..."
echo "" > coverage.txt echo "" > coverage.txt
for d in $(go list ./... | grep -v 'vendor\|cmd'); do for d in $(go list ./... | grep -v 'vendor\|cmd'); do
GOCACHE=off GOCACHE=off
go test -mod=vendor -v -race -tags test -coverprofile=profile.out -covermode=atomic $d go test -mod=vendor -v -race -tags test -coverprofile=profile.out -covermode=atomic $d
if [ -f profile.out ]; then if [ -f profile.out ]; then
cat profile.out >> coverage.txt cat profile.out >> coverage.txt
rm profile.out rm profile.out
fi fi
done done
} }
push() { push() {
if test -n "$BRANCH_NAME" && test "$BRANCH_NAME" = "master"; then if test -n "$BRANCH_NAME" && test "$BRANCH_NAME" = "master"; then
echo "Pushing Docker images..." echo "Pushing Docker images..."
make -j$NPROC latest make -j$NPROC latest
fi fi
} }
set -e set -e