1+ .PHONY : help
2+ help : # # Prints help (only for targets with comments)
3+ @grep -E ' ^[a-zA-Z._-]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | awk ' BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
4+
5+ APP =dobby
6+ SRC_PACKAGES =$(shell go list ./... | grep -v "vendor")
7+ VERSION? =1.0
8+ BUILD? =$(shell git describe --always --dirty 2> /dev/null)
9+ DEP: =$(shell command -v dep 2> /dev/null)
10+ GOLINT: =$(shell command -v golint 2> /dev/null)
11+ APP_EXECUTABLE ="./out/$(APP ) "
12+ RICHGO =$(shell command -v richgo 2> /dev/null)
13+ GOMETA_LINT =$(shell command -v golangci-lint 2> /dev/null)
14+ GOLANGCI_LINT_VERSION =v1.12.5
15+ GO111MODULE =off
16+ SHELL =/bin/bash -o pipefail
17+
18+ ifeq ($(GOMETA_LINT ) ,)
19+ GOMETA_LINT=$(shell command -v $(PWD)/bin/golangci-lint 2> /dev/null)
20+ endif
21+
22+ ifeq ($(RICHGO ) ,)
23+ GO_BINARY=go
24+ else
25+ GO_BINARY=richgo
26+ endif
27+
28+ ifeq ($(BUILD ) ,)
29+ BUILD=dev
30+ endif
31+
32+ ifdef CI_COMMIT_SHORT_SHA
33+ BUILD=$(CI_COMMIT_SHORT_SHA)
34+ endif
35+
36+ all : setup build
37+
38+ ensure-build-dir :
39+ mkdir -p out
40+
41+ build-deps : # # Install dependencies
42+ dep ensure -v
43+
44+ compile : ensure-build-dir # # Compile dobby
45+ $(GO_BINARY ) build -ldflags " -X main.majorVersion=$( VERSION) -X main.minorVersion=${BUILD} " -o $(APP_EXECUTABLE ) ./main.go
46+
47+ run : compile # # Run dobby
48+ ./out/dobby server
49+
50+ compile-linux : ensure-build-dir # # Compile dobby for linux
51+ GOOS=linux GOARCH=amd64 $(GO_BINARY ) build -ldflags " -X main.majorVersion=$( VERSION) -X main.minorVersion=${BUILD} " -o $(APP_EXECUTABLE ) ./main.go
52+
53+ build : build-deps fmt vet lint-all compile # # Build the application
54+
55+ compress : compile # # Compress the binary
56+ upx $(APP_EXECUTABLE )
57+
58+ fmt :
59+ $(GO_BINARY ) fmt $(SRC_PACKAGES )
60+
61+ vet :
62+ $(GO_BINARY ) vet $(SRC_PACKAGES )
63+
64+ setup-golangci-lint :
65+ ifeq ($(GOMETA_LINT ) ,)
66+ curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s $(GOLANGCI_LINT_VERSION)
67+ endif
68+
69+ setup : setup-golangci-lint ensure-build-dir # # Setup environment
70+ ifeq ($(DEP ) ,)
71+ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
72+ endif
73+ ifeq ($(GOLINT ) ,)
74+ $(GO_BINARY) get -u golang.org/x/lint/golint
75+ endif
76+ ifeq ($(RICHGO ) ,)
77+ $(GO_BINARY) get -u github.com/kyoh86/richgo
78+ endif
79+
80+ lint-all : lint setup-golangci-lint
81+ $(GOMETA_LINT ) run
82+
83+ lint :
84+ ./scripts/lint $(SRC_PACKAGES )
85+
86+ test-all : test test.integration
87+
88+ test : ensure-build-dir # # Run tests
89+ ENVIRONMENT=test $(GO_BINARY ) test $(SRC_PACKAGES ) -p=1 -coverprofile ./out/coverage -short -v | grep -vi " start" | grep -vi " no test files"
90+
91+ test-cover-html : # # Run tests with coverage
92+ mkdir -p ./out
93+ @echo " mode: count" > coverage-all.out
94+ $(foreach pkg, $(SRC_PACKAGES ) ,\
95+ ENVIRONMENT=test $(GO_BINARY ) test -coverprofile=coverage.out -covermode=count $(pkg ) ; \
96+ tail -n +2 coverage.out >> coverage-all.out; )
97+ $(GO_BINARY ) tool cover -html=coverage-all.out -o out/coverage.html
0 commit comments