From 3bf5374a41c0a5e49165fd34ad28ce50c73219a1 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Sat, 18 Aug 2018 16:20:07 -0700 Subject: [PATCH] Better CI, care of Pantomath Fixes #7 --- .gitlab-ci.yml | 71 ++++++++++++++++++++++++++++++++------------------ Makefile | 39 +++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 Makefile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e6a16c8..26370b4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,41 +1,60 @@ -# This file is a template, and might need editing before it works on your project. image: golang:latest -variables: - REPO_NAME: git.ethitter.com/debian/eth-log-alerting +cache: + paths: + - /apt-cache + - /go/src/github.com + - /go/src/golang.org + - /go/src/google.golang.org + - /go/src/gopkg.in + - /go/src/git.ethitter.com + +stages: + - test + - build -# The problem is that to be able to use go get, one needs to put -# the repository in the $GOPATH. So for example if your gitlab domain -# is gitlab.com, and that your repository is namespace/project, and -# the default GOPATH being /go, then you'd need to have your -# repository in /go/src/gitlab.com/namespace/project -# Thus, making a symbolic link corrects this. before_script: - - mkdir -p $GOPATH/src/$(dirname $REPO_NAME) - - ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME - - cd $GOPATH/src/$REPO_NAME + - mkdir -p /go/src/git.ethitter.com/debian /go/src/_/builds + - cp -r $CI_PROJECT_DIR /go/src/git.ethitter.com/debian/eth-log-alerting + - ln -s /go/src/git.ethitter.com/debian /go/src/_/builds/debian + - make dep - - go version +unit_tests: + stage: test + script: + - make test - - go get github.com/asaskevich/govalidator - - go get github.com/ashwanthkumar/slack-go-webhook - - go get github.com/hpcloud/tail +race_detector: + stage: test + script: + - make race -stages: - - test - - build +memory_sanitizer: + stage: test + script: + - make msan + +code_coverage: + stage: test + script: + - make coverage + +code_coverage_report: + stage: test + script: + - make coverhtml + only: + - master -format: +lint_code: stage: test script: - - go tool vet -composites=false -shadow=true *.go - - go test -race $(go list ./... | grep -v /vendor/) + - make lint -compile: +build: stage: build script: - - go get github.com/mitchellh/gox - - gox -output="eth-log-alerting-builds/{{.Dir}}_{{.OS}}_{{.Arch}}" -parallel=4 + - make artifacts: paths: - - eth-log-alerting-builds/ + - eth-log-alerting-builds/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e9574f2 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +PROJECT_NAME := "eth-log-alerting" +PKG := "git.ethitter.com/debian/$(PROJECT_NAME)" +PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/) +GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go) + +.PHONY: all dep build clean test coverage coverhtml lint + +all: build + +lint: + @golint -set_exit_status ${PKG_LIST} + +test: + @go test -short ${PKG_LIST} + +race: dep + @go test -race -short ${PKG_LIST} + +msan: dep + @go test -msan -short ${PKG_LIST} + +coverage: + ./tools/coverage.sh; + +coverhtml: + ./tools/coverage.sh html; + +dep: + @go get -v -d ./... + @go get github.com/mitchellh/gox + +build: dep + @gox -output="eth-log-alerting-builds/{{.Dir}}_{{.OS}}_{{.Arch}}" -parallel=4 + +clean: + @rm -f $(PROJECT_NAME) + +help: + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' -- GitLab