forked from temporalio/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (102 loc) · 4.43 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
126
127
128
129
130
131
132
.PHONY: test bins clean cover cover-ci check errcheck staticcheck lint fmt
# default target
default: check test
# general build-product folder, cleaned as part of `make clean`
BUILD := .build
TEST_TIMEOUT := 3m
TEST_ARG ?= -race -v -timeout $(TEST_TIMEOUT)
INTEG_TEST_ROOT := ./test
COVER_ROOT := $(BUILD)/coverage
UT_COVER_FILE := $(COVER_ROOT)/unit_test_cover.out
INTEG_ZERO_CACHE_COVER_FILE := $(COVER_ROOT)/integ_test_zero_cache_cover.out
INTEG_NORMAL_CACHE_COVER_FILE := $(COVER_ROOT)/integ_test_normal_cache_cover.out
# Automatically gather all srcs
ALL_SRC := $(shell find . -name "*.go")
UT_DIRS := $(filter-out $(INTEG_TEST_ROOT)%, $(sort $(dir $(filter %_test.go,$(ALL_SRC)))))
INTEG_TEST_DIRS := $(sort $(dir $(shell find $(INTEG_TEST_ROOT) -name *_test.go)))
# Files that needs to run lint. Excludes testify mocks.
LINT_SRC := $(filter-out ./mocks/%,$(ALL_SRC))
# `make copyright` or depend on "copyright" to force-run licensegen,
# or depend on $(BUILD)/copyright to let it run as needed.
copyright $(BUILD)/copyright:
go run ./internal/cmd/tools/copyright/licensegen.go --verifyOnly
@mkdir -p $(BUILD)
@touch $(BUILD)/copyright
$(BUILD)/dummy:
go build -o $@ internal/cmd/dummy/dummy.go
bins: $(BUILD)/copyright $(BUILD)/dummy
unit-test: $(BUILD)/dummy
@mkdir -p $(COVER_ROOT)
@echo "mode: atomic" > $(UT_COVER_FILE)
@for dir in $(UT_DIRS); do \
mkdir -p $(COVER_ROOT)/"$$dir"; \
go test "$$dir" $(TEST_ARG) -coverprofile=$(COVER_ROOT)/"$$dir"/cover.out || exit 1; \
cat $(COVER_ROOT)/"$$dir"/cover.out | grep -v "mode: atomic" >> $(UT_COVER_FILE); \
done;
integration-test-zero-cache: $(BUILD)/dummy
@mkdir -p $(COVER_ROOT)
@for dir in $(INTEG_TEST_DIRS); do \
WORKFLOW_CACHE_SIZE=0 go test $(TEST_ARG) "$$dir" -coverprofile=$(INTEG_ZERO_CACHE_COVER_FILE) -coverpkg=./... || exit 1; \
done;
integration-test-normal-cache: $(BUILD)/dummy
@mkdir -p $(COVER_ROOT)
@for dir in $(INTEG_TEST_DIRS); do \
go test $(TEST_ARG) "$$dir" -coverprofile=$(INTEG_NORMAL_CACHE_COVER_FILE) -coverpkg=./... || exit 1; \
done;
test: unit-test integration-test-zero-cache integration-test-normal-cache
$(COVER_ROOT)/cover.out: $(UT_COVER_FILE) $(INTEG_ZERO_CACHE_COVER_FILE) $(INTEG_NORMAL_CACHE_COVER_FILE)
@echo "mode: atomic" > $(COVER_ROOT)/cover.out
cat $(UT_COVER_FILE) | grep -v "^mode: \w\+" | grep -v ".gen" >> $(COVER_ROOT)/cover.out
cat $(INTEG_ZERO_CACHE_COVER_FILE) | grep -v "^mode: \w\+" | grep -v ".gen" >> $(COVER_ROOT)/cover.out
cat $(INTEG_NORMAL_CACHE_COVER_FILE) | grep -v "^mode: \w\+" | grep -v ".gen" >> $(COVER_ROOT)/cover.out
cover: $(COVER_ROOT)/cover.out
go tool cover -html=$(COVER_ROOT)/cover.out;
cover_ci: $(COVER_ROOT)/cover.out
goveralls -coverprofile=$(COVER_ROOT)/cover.out -service=buildkite || echo -e "\x1b[31mCoveralls failed\x1b[m";
# golint fails to report many lint failures if it is only given a single file
# to work on at a time, and it can't handle multiple packages at once, *and*
# we can't exclude files from its checks, so for best results we need to give
# it a whitelist of every file in every package that we want linted, per package.
#
# so lint + this golint func works like:
# - iterate over all lintable dirs (outputs "./folder/")
# - find .go files in a dir (via wildcard, so not recursively)
# - filter to only files in LINT_SRC
# - if it's not empty, run golint against the list
define lint_if_present
test -n "$1" && golint -set_exit_status $1
endef
lint: $(ALL_SRC)
GO111MODULE=off go get -u golang.org/x/lint/golint
@$(foreach pkg,\
$(sort $(dir $(LINT_SRC))), \
$(call lint_if_present,$(filter $(wildcard $(pkg)*.go),$(LINT_SRC))) || ERR=1; \
) test -z "$$ERR" || exit 1
@OUTPUT=`gofmt -l $(ALL_SRC) 2>&1`; \
if [ "$$OUTPUT" ]; then \
echo "Run 'make fmt'. gofmt must be run on the following files:"; \
echo "$$OUTPUT"; \
exit 1; \
fi
vet: $(ALL_SRC)
go vet ./...
staticcheck: $(ALL_SRC)
GO111MODULE=off go get -u honnef.co/go/tools/cmd/staticcheck
staticcheck ./...
errcheck: $(ALL_SRC)
GO111MODULE=off go get -u github.com/kisielk/errcheck
errcheck ./...
fmt:
@gofmt -w $(ALL_SRC)
clean:
rm -rf $(BUILD)
check: lint vet errcheck staticcheck copyright bins
##### Fossa #####
fossa-install:
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install.sh | bash
fossa-init:
fossa init --include-all --no-ansi
fossa-analyze:
fossa analyze --no-ansi -b $${BUILDKITE_BRANCH:-$$(git branch --show-current)}
fossa-test:
fossa test --timeout 1800 --no-ansi