-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
147 lines (120 loc) · 3.98 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# based on https://gist.github.com/azatoth/1030091
define GOMMON_MAKEFILE_HELP_MSG
Make commands for gommon
help show help
Dev:
install install binaries under ./cmd to $$GOPATH/bin
fmt goimports
test unit test
generate generate code using gommon
loc lines of code (cloc required, brew install cloc)
Build:
install install all binaries under ./cmd to $$GOPATH/bin
build compile all binary to ./build for current platform
build-linux compile all linux binary to ./build with -linux suffix
build-mac compile all mac binary to ./build with -mac suffix
build-win compile all windows binary to ./build with -win suffix
build-release compile binary for all platforms and generate tarball to ./build
Docker:
docker-build build runner image w/ all binaries using mulitstage build
docker-push push runner image to docker registry
endef
export GOMMON_MAKEFILE_HELP_MSG
# TODO: might have a help verbose to and put build and docker commands in it
.PHONY: help
help:
@echo "$$GOMMON_MAKEFILE_HELP_MSG"
GO = GO111MODULE=on go
# -- build vars ---
PKGS =./errors/... ./generator/... ./httpclient/... ./log/... ./noodle/... ./util/...
PKGST =./cmd ./errors ./generator ./httpclient ./log ./noodle ./util
VERSION = 0.0.13
BUILD_COMMIT := $(shell git rev-parse HEAD)
BUILD_TIME := $(shell date +%Y-%m-%dT%H:%M:%S%z)
CURRENT_USER = $(USER)
FLAGS = -X main.version=$(VERSION) -X main.commit=$(BUILD_COMMIT) -X main.buildTime=$(BUILD_TIME) -X main.buildUser=$(CURRENT_USER)
DOCKER_REPO = dyweb/gommon
# -- build vars ---
.PHONY: install
install: fmt test
cd ./cmd/gommon && $(GO) install -ldflags "$(FLAGS)" .
mv $(GOPATH)/bin/gommonbin $(GOPATH)/bin/gommon
.PHONY: fmt
fmt:
goimports -d -l -w $(PKGST)
# --- build ---
.PHONY: clean build build-linux build-mac build-win build-all
clean:
rm -f ./build/gommon
rm -f ./build/gommon-*
build:
$(GO) build -ldflags "$(FLAGS)" -o ./build/gommon ./cmd/gommon
build-linux:
GOOS=linux GOARCH=amd64 $(GO) build -ldflags "$(FLAGS)" -o ./build/gommon-linux ./cmd/gommon
build-mac:
GOOS=darwin GOARCH=amd64 $(GO) build -ldflags "$(FLAGS)" -o ./build/gommon-mac ./cmd/gommon
build-win:
GOOS=windows GOARCH=amd64 $(GO) build -ldflags "$(FLAGS)" -o ./build/gommon-win ./cmd/gommon
build-all: build build-linux build-mac build-win
build-release: clean build-all
zip ./build/gommon-linux.zip ./build/gommon-linux
zip ./build/gommon-mac.zip ./build/gommon-mac
zip ./build/gommon-win.zip ./build/gommon-win
# --- build ---
.PHONY: generate
generate:
gommon generate -v
# --- test ---
.PHONY: test test-cover test-cover-html test-race
.PHONY: test-log test-errors
test:
$(GO) test -cover $(PKGS)
test-verbose:
$(GO) test -v -cover $(PKGS)
test-cover:
# https://github.com/codecov/example-go
$(GO) test -coverprofile=coverage.txt -covermode=atomic $(PKGS)
test-cover-html: test-cover
$(GO) tool cover -html=coverage.txt
test-race:
$(GO) test -race $(PKGS)
test-log:
$(GO) test -v -cover ./log/...
test-errors:
$(GO) test -v -cover ./errors/...
# --- test ---
# TODO: refer tools used in https://github.com/360EntSecGroup-Skylar/goreporter
.PHONY: vet
vet:
$(GO) vet $(PKGS)
.PHONY: doc
doc:
xdg-open http://localhost:6060/pkg/github.com/dyweb/gommon &
godoc -http=":6060"
# TODO: ignore example, test, legacy etc.
# https://github.com/Aaronepower/tokei
.PHONY: loc
loc:
tokei .
# --- dependency management ---
mod-init:
$(GO) mod init
mod-update:
$(GO) mod tidy
mod-graph:
$(GO) mod graph
# --- dependency management ---
# --- docker ---
.PHONY: docker-build docker-push docker-test
docker-build:
docker build -t $(DOCKER_REPO):$(VERSION) .
docker-push:
docker push $(DOCKER_REPO):$(VERSION)
docker-test:
docker-compose -f hack/docker-compose.yml run --rm golang1.12
# TODO: not sure why the latest one is not using ...
# docker-compose -f hack/docker-compose.yml run --rm golanglatest
#.PHONY: docker-remove-all-containers
#docker-remove-all-containers:
# docker rm $(shell docker ps -a -q)
# --- docker ---