-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
125 lines (94 loc) · 4.21 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
.PHONY: all deps docker docker-cgo clean docs test test-race fmt lint install deploy-docs
TAGS =
INSTALL_DIR = $(GOPATH)/bin
DEST_DIR = ./target
PATHINSTBIN = $(DEST_DIR)/bin
PATHINSTDOCKER = $(DEST_DIR)/docker
VERSION := $(shell git describe --tags || echo "v0.0.0")
VER_CUT := $(shell echo $(VERSION) | cut -c2-)
VER_MAJOR := $(shell echo $(VER_CUT) | cut -f1 -d.)
VER_MINOR := $(shell echo $(VER_CUT) | cut -f2 -d.)
VER_PATCH := $(shell echo $(VER_CUT) | cut -f3 -d.)
VER_RC := $(shell echo $(VER_PATCH) | cut -f2 -d-)
DATE := $(shell date +"%Y-%m-%dT%H:%M:%SZ")
# Dependency versions
GOLANGCI_VERSION = v1.60.3
SWAGGO_VERSION = $(shell go list -m -f '{{.Version}}' github.com/swaggo/swag)
MOCKGEN_VERSION = $(shell go list -m -f '{{.Version}}' go.uber.org/mock)
PROTOC_VERSION = 26.1
PROTOC_GEN_GO_VERSION = 1.30.0
PROTOC_GEN_GO_GRPC_VERSION = 1.3.0
LD_FLAGS =
GO_FLAGS =
DOCS_FLAGS =
APPS = device-definitions-api
all: $(APPS)
install: $(APPS)
@mkdir -p bin
@cp $(PATHINSTBIN)/device-definitions-api ./bin/
deps:
@go mod tidy
@go mod vendor
SOURCE_FILES = $(shell find lib internal -type f -name "*.go")
$(PATHINSTBIN)/%: $(SOURCE_FILES)
@go build $(GO_FLAGS) -tags "$(TAGS)" -ldflags "$(LD_FLAGS) " -o $@ ./cmd/$*
$(APPS): %: $(PATHINSTBIN)/%
gen-proto:
@protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative pkg/grpc/*.proto
gen-swag:
@swag init -g cmd/device-definitions-api/main.go --parseDependency --parseInternal
add-migration:
goose -dir internal/infrastructure/db/migrations create rename_me sql
migrate:
@go run ./cmd/device-definitions-api migrate
sqlboiler:
@sqlboiler psql --no-tests --wipe
docker-tags:
@echo "latest,$(VER_CUT),$(VER_MAJOR).$(VER_MINOR),$(VER_MAJOR)" > .tags
docker-rc-tags:
@echo "latest,$(VER_CUT),$(VER_MAJOR)-$(VER_RC)" > .tags
docker-cgo-tags:
@echo "latest-cgo,$(VER_CUT)-cgo,$(VER_MAJOR).$(VER_MINOR)-cgo,$(VER_MAJOR)-cgo" > .tags
docker: deps
@docker build -f ./resources/docker/Dockerfile . -t dimozone/device-definitions-api:$(VER_CUT)
@docker tag dimozone/device-definitions-api:$(VER_CUT) dimozone/device-definitions-api:latest
tools-golangci-lint: ## install golangci-lint
@mkdir -p $(PATHINSTBIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINARY=golangci-lint bash -s -- ${GOLANGCI_VERSION}
tools-swagger: ## install swagger tool
@mkdir -p $(PATHINSTBIN)
GOBIN=$(PATHINSTBIN) go install github.com/swaggo/swag/cmd/swag@$(SWAGGO_VERSION)
tools-mockgen: ## install mockgen tool
@mkdir -p $(PATHINSTBIN)
GOBIN=$(PATHINSTBIN) go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)
tools-protoc:
@mkdir -p bin/protoc
ifeq ($(shell uname | tr A-Z a-z), darwin)
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-osx-x86_64.zip > bin/protoc.zip
endif
ifeq ($(shell uname | tr A-Z a-z), linux)
curl -L https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip > bin/protoc.zip
endif
unzip bin/protoc.zip -d bin/protoc
rm bin/protoc.zip
tools-protoc-gen-go:
@mkdir -p bin
curl -L https://github.com/protocolbuffers/protobuf-go/releases/download/v${PROTOC_GEN_GO_VERSION}/protoc-gen-go.v${PROTOC_GEN_GO_VERSION}.$(shell uname | tr A-Z a-z).amd64.tar.gz | tar -zOxf - protoc-gen-go > ./bin/protoc-gen-go
@chmod +x ./bin/protoc-gen-go
tools-protoc-gen-go-grpc:
@mkdir -p bin
curl -L https://github.com/grpc/grpc-go/releases/download/cmd/protoc-gen-go-grpc/v${PROTOC_GEN_GO_GRPC_VERSION}/protoc-gen-go-grpc.v${PROTOC_GEN_GO_GRPC_VERSION}.$(shell uname | tr A-Z a-z).amd64.tar.gz | tar -zOxf - ./protoc-gen-go-grpc > ./bin/protoc-gen-go-grpc
@chmod +x ./bin/protoc-gen-go-grpc
make tools: tools-golangci-lint tools-swagger tools-mockgen tools-protoc tools-protoc-gen-go tools-protoc-gen-go-grpc## install all tools
fmt:
@go list -f {{.Dir}} ./... | xargs -I{} gofmt -w -s {}
@go mod tidy
lint:
golangci-lint run
test: $(APPS)
@go test $(GO_FLAGS) -timeout 3m -race ./...
@$(PATHINSTBIN)/device-definitions-api test ./config/test/...
clean:
rm -rf $(PATHINSTBIN)
rm -rf $(DEST_DIR)/dist
rm -rf $(PATHINSTDOCKER)