-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
80 lines (67 loc) · 2.67 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
default: build
GO_TOOLS_BIN_PATH := $(shell pwd)/.tools/bin
PATH := $(GO_TOOLS_BIN_PATH):$(PATH)
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash)
install-tools:
@ echo "install-tools ..."
@ mkdir -p $(GO_TOOLS_BIN_PATH)
@ (which golangci-lint && golangci-lint version | grep '1.49') >/dev/null 2>&1 || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_TOOLS_BIN_PATH) v1.49.0
@ grep '_' toolset/toolset.go | sed 's/"//g' | awk '{print $$2}' | xargs go install
ALL_PKG := github.com/tatris-io/tatris
PACKAGES := $(shell go list ./...)
PACKAGE_DIRECTORIES := $(subst $(ALL_PKG)/,,$(PACKAGES))
PACKAGES_WITHOUT_TOOLSET := $(shell go list ./... | sed '/^github.com\/tatris-io\/tatris\/toolset/d')
REVISION := $(shell git rev-parse --short HEAD 2>/dev/null)
REVISION_DATE := $(shell git log -1 --pretty=format:'%ad' --date short 2>/dev/null)
BUILD_TIME=$(shell date +%Y-%m-%d-%H:%M:%S)
VERSION_PKG := github.com/tatris-io/tatris/internal/common/consts
LDFLAGS = -s -w
ifneq ($(strip $(REVISION)),)
LDFLAGS += -X $(VERSION_PKG).revision=$(REVISION) \
-X $(VERSION_PKG).revisionDate=$(REVISION_DATE) \
-X $(VERSION_PKG).buildTime=$(BUILD_TIME)
endif
DOCKER_BUILD_ARGS := -f docker/Dockerfile --build-arg GOLANG_LDFLAGS="$(LDFLAGS)" .
ifdef TARGETPLATFORM
DOCKER_BUILD_ARGS := --platform $(TARGETPLATFORM) $(DOCKER_BUILD_ARGS)
endif
ifdef TAG
DOCKER_BUILD_ARGS := --load -t $(TAG) $(DOCKER_BUILD_ARGS)
endif
ifdef GOPROXY
DOCKER_BUILD_ARGS := --build-arg GOPROXY=$(GOPROXY) $(DOCKER_BUILD_ARGS)
endif
check: install-tools
@ echo "do checks ..."
@ make check-license
@ echo "gofmt ..."
@ gofmt -s -l -w $(PACKAGE_DIRECTORIES)
@ echo "golines ..."
@ golines --max-len=100 --shorten-comments -w internal cmd test
@ echo "golangci-lint ..."
@ golangci-lint cache clean
@ golangci-lint run -c golangci-lint.yml ./internal/... ./cmd/...
@ echo "revive ..."
@ revive -formatter friendly -config revive.toml $(PACKAGES_WITHOUT_TOOLSET)
test: install-tools
@ echo "unit test ..."
@ go test -timeout 5m -race -cover $(PACKAGES_WITHOUT_TOOLSET)
check-license:
@ echo "check-license ..."
@ sh ./scripts/check-license.sh
add-license:
@ echo "add-license ..."
@ sh ./scripts/add-license.sh
build: check fast-build
fast-build:
@ echo "building ..."
@ mkdir -p ./bin
@ go build -ldflags="$(LDFLAGS)" -o ./bin/tatris-meta ./cmd/meta/...
@ go build -ldflags="$(LDFLAGS)" -o ./bin/tatris-server ./cmd/server/...
docker-image:
@ echo "building docker image, args: $(DOCKER_BUILD_ARGS)"
@ docker buildx build $(DOCKER_BUILD_ARGS)
clean:
@ echo "clean ..."
@ rm -f ./bin/tatris-meta
@ rm -f ./bin/tatris-server