forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.Common
131 lines (108 loc) · 3.69 KB
/
Makefile.Common
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
# SRC_ROOT is the top of the source tree.
SRC_ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
ALL_SRC := $(shell find . -name '*.go' \
-not -path '*/third_party/*' \
-type f | sort)
# All source code and documents. Used in spell check.
ALL_SRC_AND_DOC := $(shell find . \( -name "*.md" -o -name "*.go" -o -name "*.yaml" \) \
-type f | sort)
# ALL_PKGS is used with 'go cover'
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))) 2>/dev/null)
# ALL_MODULES includes ./* dirs (excludes . dir)
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort | egrep '^./' )
GOTEST_OPT?= -race -timeout 30s
GOTEST_INTEGRATION_OPT?= -race -timeout 60s
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
GOTEST_OPT_WITH_INTEGRATION=$(GOTEST_INTEGRATION_OPT) -v -tags=integration -run=Integration -coverprofile=integration-coverage.txt -covermode=atomic
GOTEST=go test
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
ADDLICENCESE= addlicense
MISSPELL=misspell -error
MISSPELL_CORRECTION=misspell -w
STATICCHECK=staticcheck
LINT=golangci-lint
IMPI=impi
# BUILD_TYPE should be one of (dev, release).
BUILD_TYPE?=release
all-modules:
@echo $(ALL_MODULES) | tr ' ' '\n' | sort
all-pkgs:
@echo $(ALL_PKGS) | tr ' ' '\n' | sort
all-srcs:
@echo $(ALL_SRC) | tr ' ' '\n' | sort
.DEFAULT_GOAL := common
.PHONY: common
common: checklicense impi lint misspell test
.PHONY: test
test:
@set -e; for dir in $(ALL_MODULES); do \
echo "go test ./... in $${dir}"; \
(cd "$${dir}" && \
$(GOTEST) ./... ); \
done
.PHONY: do-unit-tests-with-cover
do-unit-tests-with-cover:
@echo "running go unit test ./... + coverage in `pwd`"
@$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) ./...
go tool cover -html=coverage.txt -o coverage.html
.PHONY: run-integration-tests-with-cover
do-integration-tests-with-cover:
@echo "running go integration test ./... + coverage in `pwd`"
@$(GOTEST) $(GOTEST_OPT_WITH_INTEGRATION) ./...
@if [ -e integration-coverage.txt ]; then \
go tool cover -html=integration-coverage.txt -o integration-coverage.html; \
fi
.PHONY: benchmark
benchmark:
$(GOTEST) -bench=. -run=notests $(ALL_PKGS)
.PHONY: addlicense
addlicense:
@ADDLICENCESEOUT=`$(ADDLICENCESE) -y -c 'OpenTelemetry Authors' $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENCESEOUT" ]; then \
echo "$(ADDLICENCESE) FAILED => add License errors:\n"; \
echo "$$ADDLICENCESEOUT\n"; \
exit 1; \
else \
echo "Add License finished successfully"; \
fi
.PHONY: checklicense
checklicense:
@ADDLICENCESEOUT=`$(ADDLICENCESE) -check $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENCESEOUT" ]; then \
echo "$(ADDLICENCESE) FAILED => add License errors:\n"; \
echo "$$ADDLICENCESEOUT\n"; \
echo "Use 'make addlicense' to fix this."; \
exit 1; \
else \
echo "Check License finished successfully"; \
fi
.PHONY: lint-static-check
lint-static-check:
@STATIC_CHECK_OUT=`$(STATICCHECK) ./... 2>&1`; \
if [ "$$STATIC_CHECK_OUT" ]; then \
echo "$(STATICCHECK) FAILED => static check errors:\n"; \
echo "$$STATIC_CHECK_OUT\n"; \
exit 1; \
else \
echo "Static check finished successfully"; \
fi
.PHONY: fmt
fmt:
gofmt -w -s ./
goimports -w -local github.com/open-telemetry/opentelemetry-collector-contrib ./
.PHONY: lint
lint: lint-static-check
$(LINT) run --allow-parallel-runners
.PHONY: misspell
misspell:
$(MISSPELL) $(ALL_SRC_AND_DOC)
.PHONY: misspell-correction
misspell-correction:
$(MISSPELL_CORRECTION) $(ALL_SRC_AND_DOC)
.PHONY: impi
impi:
@$(IMPI) --local github.com/open-telemetry/opentelemetry-collector-contrib --scheme stdThirdPartyLocal ./...
.PHONY: dep
dep:
go mod download