-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
105 lines (81 loc) · 2.3 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
104
105
-include .env
CURRENT_DIR = $(shell realpath .)
MODULE_DIRS = $(shell find $(CURRENT_DIR) -name go.mod -exec dirname {} \;)
DOCKER_IMAGE = $(shell basename -s .git $(shell git config --get remote.origin.url))
DOCKER_TAG = $(shell git tag --sort=-v:refname | grep -v '/' | head -n 1 || echo "latest")
DOCKERFILE = deployments/Dockerfile
CGO_ENABLED ?= 1
.PHONY: init generate build clean tidy update sync check test coverage benchmark lint fmt vet doc docker-build
all: lint test build
init:
@cp .go.work go.work
@$(MAKE) install-tools
@$(MAKE) install-modules
install-tools:
@go install golang.org/x/tools/cmd/godoc@latest
@go install golang.org/x/tools/cmd/goimports@latest
@go install honnef.co/go/tools/cmd/staticcheck@latest
install-modules:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go install -v ./...; \
done
generate:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go generate ./...; \
done
build:
@go clean -cache
@mkdir -p dist
@cd cmd && CGO_ENABLED=$(CGO_ENABLED) go build -ldflags "-s -w" -o ../dist ./...
clean:
@go clean -cache
@rm -rf dist
tidy:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go mod tidy; \
done
update:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go get -u all && go mod tidy; \
done
clean-cache:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go clean -modcache; \
done
sync:
@go work sync
check: lint test staticcheck
test:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go test -race $(test-options) ./...; \
done
coverage:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go test -race --coverprofile=coverage.out --covermode=atomic $(test-options) ./...; \
cat coverage.out >> $(CURRENT_DIR)/coverage.out && rm coverage.out; \
done
benchmark:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go test -run="-" -bench=".*" -benchmem $(test-options) ./...; \
done
lint: fmt vet staticcheck
fmt:
@for dir in $(MODULE_DIRS); do \
cd $$dir && goimports -w .; \
done
vet:
@for dir in $(MODULE_DIRS); do \
cd $$dir && go vet ./...; \
done
staticcheck:
@for dir in $(MODULE_DIRS); do \
cd $$dir && staticcheck ./...; \
done
doc: init
@godoc -http=:6060
docker-build:
docker build --no-cache \
-t $(if $(DOCKER_DOMAIN),$(DOCKER_DOMAIN)/)$(DOCKER_IMAGE):$(DOCKER_TAG) \
-f $(DOCKERFILE) \
--build-arg COPY_EXAMPLES=$(COPY_EXAMPLES) \
$(CURRENT_DIR)