generated from nezorflame/example-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
99 lines (82 loc) · 2.18 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
CMD:=armenian-blackouts-bot
PKG_LIST:=$(shell go list -f '{{.Dir}}' ./...)
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
export GOPROXY=https://proxy.golang.org
BUILD_ENVPARMS:=CGO_ENABLED=0
BUILD_TS:=$(shell date +%FT%T%z)
PWD:=$(PWD)
export PATH:=$(PWD)/bin:$(PATH)
# init the project (do this once!)
.PHONY: init
init: workspace deps tools
# setup Go module workspace
.PHONY: workspace
workspace:
$(info #Setting up the workspace...)
go work init
go work use .
go work use tools
# install project dependencies
.PHONY: deps
deps:
$(info #Installing dependencies...)
go mod download
# install project dependencies with tidy
.PHONY: tidy
tidy:
$(info #Installing dependencies and cleaning up...)
go mod tidy
.PHONY: update
update:
$(info #Updating dependencies...)
go get -d -mod= -u
.PHONY: generate
generate:
$(info #Generating code...)
go generate ./...
.PHONY: format
format:
$(info #Formatting code...)
golangci-lint run --fix ./...
.PHONY: refresh
refresh: generate format deps
# run all tests
.PHONY: test
test: deps
$(info #Running tests...)
go test -v -race ./...
# run all tests with coverage
.PHONY: test-cover
test-cover: deps
$(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...)
$(shell $(BUILD_ENVPARMS) go build -o bin/$(CMD) .)
@echo
.PHONY: build
build: deps fast-build test
.PHONY: install
install: deps
$(info #Installing binaries...)
$(shell $(BUILD_ENVPARMS) go install .)
@echo
# install tools binary: linter, mockgen, etc.
.PHONY: tools
tools:
$(info #Installing tools...)
cd tools && go mod tidy && go generate -tags tools
# run linter
.PHONY: lint
lint:
$(info #Running lint...)
golangci-lint run ./...