-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
52 lines (45 loc) · 1.99 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
CMD_LIST?=$(shell ls ./cmd)
PKG_LIST:=$(shell go list ./...)
GIT_HASH?=$(shell git log --format="%h" -n 1 2> /dev/null)
GIT_BRANCH?=$(shell git branch 2> /dev/null | grep '*' | cut -f2 -d' ')
GIT_TAG:=$(shell git describe --exact-match --abbrev=0 --tags 2> /dev/null)
APP_VERSION?=$(if $(GIT_TAG),$(GIT_TAG),$(shell git describe --all --long HEAD 2> /dev/null))
GO_VERSION:=$(shell go version)
GO_VERSION_SHORT:=$(shell echo $(GO_VERSION)|sed -E 's/.* go(.*) .*/\1/g')
export GO111MODULE=on
BUILD_ENVPARMS:=CGO_ENABLED=0
BUILD_TS:=$(shell date +%FT%T%z)
LDFLAGS:=-X 'github.com/nezorflame/speech-recognition-bot/internal/app.Version=$(APP_VERSION)'\
-X 'github.com/nezorflame/speech-recognition-bot/internal/app.BuildTS=$(BUILD_TS)'\
-X 'github.com/nezorflame/speech-recognition-bot/internal/app.GoVersion=$(GO_VERSION_SHORT)'\
-X 'github.com/nezorflame/speech-recognition-bot/internal/app.GitHash=$(GIT_HASH)'\
-X 'github.com/nezorflame/speech-recognition-bot/internal/app.GitBranch=$(GIT_BRANCH)'\
# install project dependencies
.PHONY: deps
deps:
$(info #Install dependencies and clean up...)
go mod tidy
# run all tests
.PHONY: test
test:
$(info #Running tests...)
go test -v -cover -race ./...
# run all tests with coverage
.PHONY: test-cover
test-cover:
$(info #Running tests with coverage...)
go test -v -coverprofile=coverage.out -race $(PKG_LIST)
go tool cover -func=coverage.out | grep total
rm -f coverage.out
.PHONY: fast-build
fast-build: deps
$(info #Building binaries...)
$(foreach CMD, $(CMD_LIST), $(shell $(BUILD_ENVPARMS) go build -ldflags "-s -w $(LDFLAGS) -X 'github.com/nezorflame/speech-recognition-bot/internal/app.Name=$(CMD)'" -o ./bin/$(CMD) ./cmd/$(CMD)))
@echo
.PHONY: build
build: deps fast-build test
.PHONY: install
install:
$(info #Installing binaries...)
$(foreach CMD, $(CMD_LIST), $(shell $(BUILD_ENVPARMS) go install -ldflags "-s -w $(LDFLAGS) -X 'github.com/nezorflame/speech-recognition-bot/internal/app.Name=$(CMD)'" ./cmd/$(CMD)))
@echo