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