forked from temporalio/tcld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
67 lines (52 loc) · 2.13 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
.PHONY: clean test bins lint tools
PROJECT_ROOT = github.com/temporalio/tcld
# default target
default: clean test bins
TAG_COMMIT := $(shell git rev-list --abbrev-commit --tags --max-count=1)
TAG := $(shell git describe --abbrev=0 --tags ${TAG_COMMIT} 2>/dev/null || true)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d")
APPPKG := $(PROJECT_ROOT)/app
LINKER_FLAGS := -X $(APPPKG).BuildDate=$(DATE) -X $(APPPKG).Commit=$(COMMIT) -X $(APPPKG).Version=$(TAG)
ALL_SRC := $(shell find . -name "*.go")
TEST_DIRS := $(sort $(dir $(filter %_test.go,$(ALL_SRC))))
TEST_ARG ?= -race -timeout=5m -cover -count=1
COVER_ROOT := ./.coverage
SUMMARY_COVER_PROFILE := $(COVER_ROOT)/summary_coverprofile.out
tcld:
@go build -ldflags "$(LINKER_FLAGS)" -o tcld ./cmd/tcld/*.go
bins: clean tcld
test:
@$(foreach TEST_DIR,$(TEST_DIRS),\
go test $(TEST_ARG) $(TEST_DIR) &&) echo passed
clean:
@rm -rf ./tcld
define build
@echo "building release for $(1) $(2) $(3)..."
@mkdir -p releases
@GOOS=$(2) GOARCH=$(3) go build -ldflags "-w $(LINKER_FLAGS)" -o releases/$(1)_$(2)_$(3)$(4) ./cmd/tcld/*.go
@tar -cvzf releases/$(1)_$(2)_$(3).tar.gz releases/$(1)_$(2)_$(3)$(4) &>/dev/null
endef
release:
@rm -rf releases && mkdir -p releases
$(call build,tcld,linux,amd64)
$(call build,tcld,darwin,amd64,)
$(call build,tcld,darwin,arm64,)
$(call build,tcld,windows,amd64,.exe)
tools:
@go install github.com/golangci/golangci-lint/cmd/[email protected]
@GO111MODULE=off go get -u github.com/golang/mock/mockgen
lint:
golangci-lint run
mocks:
@mockgen -source services/loginservice.go -destination services/loginservicemock.go -package services
$(COVER_ROOT):
@mkdir -p $(COVER_ROOT)
cover: $(COVER_ROOT)
@echo "mode: atomic" > $(SUMMARY_COVER_PROFILE);\
$(foreach TEST_DIR,$(TEST_DIRS),\
mkdir -p $(COVER_ROOT)/$(TEST_DIR);\
go test $(TEST_ARG) -coverprofile=$(COVER_ROOT)/$(TEST_DIR)/coverprofile.out $(TEST_DIR);\
grep -v -e "^mode: \w\+" $(COVER_ROOT)/$(TEST_DIR)/coverprofile.out >> $(SUMMARY_COVER_PROFILE);\
$(NEWLINE))\
go tool cover -html=$(SUMMARY_COVER_PROFILE) -o $(SUMMARY_COVER_PROFILE).html