diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..3821993 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,47 @@ +image: golang:alpine + +cache: + paths: + - /go/src/github.com + - /go/src/gitlab.com + - /go/src/golang.org + - /go/src/google.golang.org + - /go/src/gopkg.in + +stages: + - test + - build + +before_script: + - apk add --no-cache git build-base bash + - mkdir -p /go/src/gitlab.com/$CI_PROJECT_NAMESPACE /go/src/_/builds + - cp -r $CI_PROJECT_DIR /go/src/gitlab.com/$CI_PROJECT_PATH + - ln -s /go/src/gitlab.com/$CI_PROJECT_NAMESPACE /go/src/_/builds/$CI_PROJECT_NAMESPACE + - make dep + +unit_tests: + stage: test + script: + - make test + +.race_detector: + stage: test + script: + - make race + +code_coverage: + stage: test + script: + - make coverage + +lint_code: + stage: test + script: + - go get github.com/go-critic/go-critic/cmd/gocritic + - go install github.com/go-critic/go-critic/cmd/gocritic + - make lint + +build: + stage: build + script: + - make \ No newline at end of file diff --git a/Makefile b/Makefile index 9f89132..705f162 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,32 @@ -# Build package by default with all general tools and things -all: - make localization - make build +PROJECT_NAMESPACE := $(CI_PROJECT_NAMESPACE) +PROJECT_NAME := $(CI_PROJECT_NAME) +PROJECT_PATH := $(PROJECT_NAMESPACE)/$(PROJECT_NAME) +PACKAGE_NAME := "gitlab.com/$(PROJECT_PATH)" +PACKAGE_PATH := $(GOPATH)/src/$(PACKAGE_NAME) +PACKAGE_LIST := $(shell go list $(PACKAGE_NAME)/... | grep -v /vendor/) +GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go) -# Build minimal package only -build: - go build +.PHONY: all lint test rase coverage dep build clean -# Build debug version with more logs -debug: - go build -tags=debug +all: build -# Format the source code -fmt: - go fmt +lint: ## Lint the files + @gocritic check-project $(PACKAGE_PATH) -check: - gometalinter --fast +race: dep ## Run data race detector + @go test -race -short ${PACKAGE_LIST} -# Build localization files with separated untranslated strings -translation: - goi18n merge -format yaml \ - -sourceLanguage en \ - -outdir ./i18n/ \ - ./i18n/src/*/* +coverage: ## Generate global code coverage report + @go test -cover -v -coverpkg=$(PACKAGE_NAME) ${PACKAGE_LIST} -# Build localization files and merge untranslated strings -localization: - make translation - goi18n -format yaml \ - -sourceLanguage en \ - -outdir ./i18n/ \ - ./i18n/*.all.yaml ./i18n/*.untranslated.yaml \ No newline at end of file +dep: ## Get the dependencies + @go get -v -d -t ${PACKAGE_LIST} + +build: dep ## Build the binary file + @go build -i -v $(PACKAGE_NAME) + +clean: ## Remove previous build + @rm -f $(PROJECT_NAME) + +help: ## Display this help screen + @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' \ No newline at end of file