-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
71 lines (58 loc) · 2.46 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
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git symbolic-ref -q --short HEAD)
COMMIT_HASH ?= $(shell git rev-parse --short HEAD 2>/dev/null)
DATE_FMT = +%FT%TZ # ISO 8601
BUILD_DATE ?= $(shell date "$(DATE_FMT)") # "-u" for UTC time (zero offset)
BUILD_DIR ?= bin
LDFLAGS += "-X main.version=$(VERSION) -X main.commitHash=$(COMMIT_HASH) -X main.buildDate=$(BUILD_DATE)"
.DEFAULT_GOAL: help
default: help
##@ Build
.PHONY: build
build: ## Build binaries.
@mkdir -p $(BUILD_DIR)
go build -ldflags $(LDFLAGS) -o $(BUILD_DIR)/ ./cmd/...
install: ## Install binaries.
go install -ldflags $(LDFLAGS) ./cmd/$*
##@ Generate
gen: ## Generates code and documentation (see: ./gen.go).
go generate ./...
##@ Test and Lint
.PHONY: test coverage
test: ## Test go code.
go test -ldflags $(LDFLAGS) -v -cover -race ./...
coverage: ## Test and check code coverage.
go test -ldflags $(LDFLAGS) -short ./... -coverprofile cover.out 2>/dev/null
go tool cover -func cover.out
.PHONY: lint
lint: ## See lint violations.
golangci-lint run ./...
FORMATTING_BEGIN_YELLOW = \033[0;33m
FORMATTING_BEGIN_BLUE = \033[36m
FORMATTING_END = \033[0m
.PHONY: help
help:
@printf -- "${FORMATTING_BEGIN_BLUE}%s${FORMATTING_END}\n" \
"" \
" :?~ ^?: " \
" ^Y&@@P~ ~P@@&5^ " \
" 7@@@@@@@G! J&@@@@@J Omlox Hub™ go client library. " \
" ~P@@@@@@@B7. .?B@G7. " \
" ^5&@@@@@@#?. .^ version: $(VERSION) ($(COMMIT_HASH)) " \
" ^Y&@@@@@@#J: " \
" :J#@@@@@@&Y^ " \
" .?#@@@@@@&5^ " \
" ~P?. .7B@@@@@@@P~ " \
" ~B@@@#J: !G@@@@@@@B! " \
" ^5&@@@@P. ~P@@@@@P~ " \
" :J#P~ ^5#5^ " \
" . . " \
"" \
"-----------------------------------------------------------------------" \
""
@awk 'BEGIN {\
FS = ":.*##"; \
printf "Usage: ${FORMATTING_BEGIN_BLUE}OPTION${FORMATTING_END}=<value> make ${FORMATTING_BEGIN_YELLOW}<target>${FORMATTING_END}\n"\
} \
/^[a-zA-Z0-9_-]+:.*?##/ { printf " ${FORMATTING_BEGIN_BLUE}%-36s${FORMATTING_END} %s\n", $$1, $$2 } \
/^.?.?##~/ { printf " %-46s${FORMATTING_BEGIN_YELLOW}%-46s${FORMATTING_END}\n", "", substr($$1, 6) } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)