-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
66 lines (51 loc) · 1.66 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
COMMON_SELF_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
ROOT_DIR:=$(abspath $(shell cd $(COMMON_SELF_DIR)/ && pwd -P))
OUTPUT_DIR:=$(ROOT_DIR)/_output
VERSION_PACKAGE=github.com/m01i0ng/mblog/pkg/version
ifeq ($(origin VERSION), undefined)
VERSION:=$(shell git describe --tags --always --match='v*')
endif
GIT_TREE_STATE:="dirty"
ifeq (, $(shell git status --pocelain 2>/dev/null))
GIT_TREE_STATE="clean"
endif
GIT_COMMIT:=$(shell git rev-parse HEAD)
GO_LDFLAGS += \
-X $(VERSION_PACKAGE).GitVersion=$(VERSION) \
-X $(VERSION_PACKAGE).GitCommit=$(GIT_COMMIT) \
-X $(VERSION_PACKAGE).GitTreeState=$(GIT_TREE_STATE) \
-X $(VERSION_PACKAGE).BuildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
APIROOT=$(ROOT_DIR)/pkg/proto
.PHONY: all
all: add-copyright format lint build
.PHONY: build
build: tidy
@go build -v -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/mblog $(ROOT_DIR)/cmd/mblog/main.go
.PHONY: format
format:
@gofmt -s -w ./
.PHONY: add-copyright
add-copyright:
@addlicense -v -f $(ROOT_DIR)/scripts/boilerplate.txt $(ROOT_DIR) --skip-dirs=third_party,vendor,.idea,$(OUTPUT_DIR)
.PHONY: swagger
swagger:
@swagger serve -F=swagger --no-open --port 65534 $(ROOT_DIR)/api/openapi/openapi.yaml
.PHONY: tidy
tidy:
@go mod tidy
.PHONY: clean
clean:
@-rm -vrf $(OUTPUT_DIR)
.PHONY: protoc
protoc:
@echo "======> Generate protobuf files"
@protoc \
--proto_path=$(APIROOT) \
--proto_path=$(ROOT_DIR)/third_party \
--go_out=paths=source_relative:$(APIROOT) \
--go-grpc_out=paths=source_relative:$(APIROOT) \
$(shell find $(APIROOT) -type f -name "*.proto")
.PHONY: lint
lint:
@echo "======> Run golangci to lint source codes"
@golangci-lint run -c ./.golangci.yaml ./...