-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
77 lines (59 loc) · 1.58 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
.DEFAULT_GOAL = help
vendor := vendor
target := target
bin := $(target)/bin
reports := $(target)/reports
## build: Compile binaries.
go_src := $(shell find * -name *.go -not -path "$(vendor)/*" -not -path "$(target)/*")
go_out := $(patsubst cmd/%/main.go,$(bin)/%,$(wildcard cmd/*/main.go))
.PHONY: build
build: $(go_out)
$(bin)/%: cmd/%/main.go $(go_src) | $(bin)
@go build --trimpath --ldflags='-X "main.version=$(version)"' -o=$@ $<
$(bin):
@mkdir -p $@
$(reports):
@mkdir -p $@
## install: Installs all packages.
.PHONY: install
install:
@go install ./...
## generate: Run generators.
.PHONY: generate
generate: go/generate
.PHONY: go/generate
go/generate:
@go generate ./...
## lint: Run static analysis.
.PHONY: lint
lint: go/lint
.PHONY: go/lint
go/lint:
@golangci-lint run
## tests: Run tests.
.PHONY: test tests
test tests: go/test go/race
.PHONY: go/race
go/race: $(go_src)
@go test -short -race -count=100 ./...
.PHONY: go/test
go/test: $(go_src) | $(reports)
@go test -v -covermode=atomic -coverprofile=$(reports)/cover.out ./...
## clean: Remove created resources.
.PHONY: clean
clean:
@rm -rf $(vendor) $(target)
## version: Display current version.
git_tag := $(shell git describe --tags 2>/dev/null)
git_sha := $(shell git rev-parse HEAD 2>/dev/null)
version := $(if $(git_tag),$(git_tag),(unknown on $(git_sha)))
.PHONY: version
version:
@echo "version $(version)"
## help: Display available targets.
.PHONY: help
help: Makefile
@echo "Usage: make [target]"
@echo
@echo "Targets:"
@sed -n 's/^## //p' $< | awk -F ':' '{printf " %-20s%s\n",$$1,$$2}'