This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathMakefile
129 lines (106 loc) · 3.41 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
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
GIT_SHA=$(shell git rev-parse --short HEAD)
PROJECT_ROOT = $(shell pwd)
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort )
ALL_SRC := $(shell find . -name '*.go' -type f | sort)
ADDLICENSE=addlicense
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./internal/tools' | sort)
FIELDALIGNMENT_DIRS := ./pipeline/
TOOLS_MOD_DIR := ./internal/tools
.PHONY: install-tools
install-tools:
cd $(TOOLS_MOD_DIR) && go install github.com/securego/gosec/v2/cmd/gosec@v2.9.6
cd $(TOOLS_MOD_DIR) && go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.43.0
cd $(TOOLS_MOD_DIR) && go install github.com/vektra/mockery/cmd/mockery
cd $(TOOLS_MOD_DIR) && go install github.com/google/addlicense
cd $(TOOLS_MOD_DIR) && go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment
.PHONY: test
test: vet test-only
.PHONY: test-only
test-only:
$(MAKE) for-all CMD="go test -race -coverprofile coverage.txt -coverpkg ./... ./..."
.PHONY: test-coverage
test-coverage: clean
@set -e; \
printf "" > coverage.txt; \
for dir in $(ALL_COVERAGE_MOD_DIRS); do \
(cd "$${dir}" && \
go list ./... \
| grep -v third_party \
| xargs go test -coverpkg=./... -covermode=atomic -coverprofile=coverage.out && \
go tool cover -html=coverage.out -o coverage.html); \
[ -f "$${dir}/coverage.out" ] && cat "$${dir}/coverage.out" >> coverage.txt; \
done; \
sed -i.bak -e '2,$$ { /^mode: /d; }' coverage.txt
.PHONY: bench
bench:
go test -benchmem -run=^$$ -bench ^* ./...
.PHONY: clean
clean:
$(MAKE) for-all CMD="rm -f coverage.txt.* coverage.html coverage.out"
.PHONY: tidy
tidy:
$(MAKE) for-all CMD="rm -fr go.sum"
$(MAKE) for-all CMD="go mod tidy -compat=1.17"
.PHONY: mod-update-only
mod-update-only:
$(MAKE) for-all CMD="go get -u ./..."
.PHONY: mod-update
mod-update: mod-update-only tidy
.PHONY: listmod
listmod:
@set -e; for dir in $(ALL_MODULES); do \
(echo "$${dir}"); \
done
.PHONY: lint
lint:
golangci-lint run --allow-parallel-runners ./...
.PHONY: lint-fix
lint-fix:
golangci-lint run --fix --allow-parallel-runners ./...
.PHONY: fieldalignment
fieldalignment:
fieldalignment $(FIELDALIGNMENT_DIRS)
.PHONY: fieldalignment-fix
fieldalignment-fix:
fieldalignment -fix $(FIELDALIGNMENT_DIRS)
.PHONY: vet
vet:
GOOS=darwin $(MAKE) for-all CMD="go vet ./..."
GOOS=linux $(MAKE) for-all CMD="go vet ./..."
GOOS=windows $(MAKE) for-all CMD="go vet ./..."
.PHONY: secure
secure:
gosec ./...
.PHONY: generate
generate:
go generate ./...
.PHONY: check-license
check-license:
@ADDLICENSEOUT=`$(ADDLICENSE) -check $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENSEOUT" ]; then \
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
echo "$$ADDLICENSEOUT\n"; \
echo "Use 'make add-license' to fix this."; \
exit 1; \
else \
echo "Check License finished successfully"; \
fi
.PHONY: add-license
add-license:
@ADDLICENSEOUT=`$(ADDLICENSE) -y "" -c "The OpenTelemetry Authors" $(ALL_SRC) 2>&1`; \
if [ "$$ADDLICENSEOUT" ]; then \
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
echo "$$ADDLICENSEOUT\n"; \
exit 1; \
else \
echo "Add License finished successfully"; \
fi
.PHONY: for-all
for-all:
@set -e; for dir in $(ALL_MODULES); do \
(cd "$${dir}" && $${CMD} ); \
done
.PHONY: ci-check
ci-check: vet lint check-license secure fieldalignment