-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
93 lines (69 loc) · 2.36 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
ifeq ($(CN), 1)
ENV := GOPROXY=https://goproxy.cn,direct
endif
SOURCE_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
{{end}}' ./...)
NS := github.com/projecteru2/vmihub
REVISION := $(shell git rev-parse HEAD || unknown)
BUILTAT := $(shell date +%Y-%m-%dT%H:%M:%S)
VERSION := $(shell git describe --tags $(shell git rev-list --tags --max-count=1))
GO_LDFLAGS ?= -X $(NS)/internal/version.REVISION=$(REVISION) \
-X $(NS)/internal/version.BUILTAT=$(BUILTAT) \
-X $(NS)/internal/version.VERSION=$(VERSION)
ifneq ($(KEEP_SYMBOL), 1)
GO_LDFLAGS += -s
endif
BUILD := go build -race
TEST := go test -count=1 -race -cover -gcflags=all=-l
PKGS := $$(go list ./... | grep -v -P '$(NS)/3rd|vendor/|mocks|e2e|fs|webconsole|ovn')
.PHONY: all test e2e
default: build
build: bin/vmihub
bin/vmihub: $(SOURCE_FILES)
$(BUILD) -ldflags '$(GO_LDFLAGS)' -o "$@" ./cmd/vmihub
lint:
golangci-lint run
format: vet
gofmt -s -w $$(find . -iname '*.go' | grep -v -P '\./3rd|\./vendor/|mocks')
vet:
go vet $(PKGS)
deps:
$(ENV) go mod tidy
$(ENV) go mod vendor
mock: deps
mockery --dir internal/storage --output internal/storage/mocks --name Storage
mockery --dir client/image --output client/image/mocks --all
clean:
rm -fr bin/*
setup: setup-lint
$(ENV) go install github.com/vektra/mockery/v2@latest
$(ENV) go install github.com/swaggo/swag/cmd/swag@latest
$(ENV) go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
setup-lint:
$(ENV) go install github.com/golangci/golangci-lint/cmd/[email protected]
swag:
swag init -g cmd/vmihub/main.go -o cmd/vmihub/docs
test:
ifdef RUN
$(TEST) -v -run='${RUN}' $(PKGS)
else
$(TEST) $(PKGS)
endif
e2e:
ifdef DIR
cp -f e2e/config.toml e2e/${DIR}/config.toml
cd e2e/${DIR} && ginkgo -r -p -- --config=`pwd`/config.toml
else
cd e2e && ginkgo -r -p -- --config=`pwd`/config.toml
endif
db-migrate-setup:
curl -L https://github.com/golang-migrate/migrate/releases/download/v4.17.1/migrate.linux-amd64.tar.gz | tar xvz
mv migrate /usr/local/bin/
db-migrate-create:
migrate create -ext sql -dir internal/models/migration ${table}
db-migrate-up:
migrate -database '${uri}' -path internal/models/migration up
db-migrate-down:
migrate -database '${uri}' -path internal/models/migration down ${N}
db-migrate-setver:
migrate -database '${uri}' -path internal/models/migration force ${ver}