-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathMakefile.Common
More file actions
133 lines (107 loc) · 3.9 KB
/
Copy pathMakefile.Common
File metadata and controls
133 lines (107 loc) · 3.9 KB
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
133
SHELL = /bin/bash
# ALL_PKGS is the list of all packages where ALL_SRC files reside.
ALL_PKGS := $(sort $(shell go list ./...))
# COVER_PKGS is the list of packages to include in the coverage
COVER_PKGS := $(shell go list ./... | tr "\n" ",")
CURR_MOD := $(shell go list -m | tr '/' '-' )
GOCMD?= go
GOOS := $(shell $(GOCMD) env GOOS)
GOARCH := $(shell $(GOCMD) env GOARCH)
GOTEST_TIMEOUT?=240s
# -race is not supported on windows arm64
GOTEST_OPT?= -timeout $(GOTEST_TIMEOUT) $(if $(and $(filter windows,$(GOOS)), $(filter arm64,$(GOARCH))),, -race)
# SRC_ROOT is the top of the source tree.
SRC_ROOT := $(shell git rev-parse --show-toplevel)
TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools
TOOLS_MOD_FILE := $(TOOLS_MOD_DIR)/go.mod
GO_TOOL := $(GOCMD) tool -modfile $(TOOLS_MOD_FILE)
CHLOGGEN_CONFIG := .chloggen/config.yaml
# no trailing slash
JUNIT_OUT_DIR ?= $(TOOLS_MOD_DIR)/testresults
.PHONY: test
test:
# GODEBUG=fips140=only is used to surface any FIPS-140-3 non-compliant cryptographic
# calls into the Go standard library. See: https://go.dev/doc/security/fips140#fips-140-3-mode
# disabling fips only to unblock CI. See https://github.com/open-telemetry/opentelemetry-collector/issues/13925
# GODEBUG=fips140=only $(GO_TOOL) gotestsum --packages="./..." -- $(GOTEST_OPT)
$(GO_TOOL) gotestsum --packages="./..." -- $(GOTEST_OPT)
.PHONY: test-with-cover
test-with-cover:
mkdir -p $(PWD)/coverage/unit
$(GO_TOOL) gotestsum \
--packages="./..." -- \
$(GOTEST_OPT) -cover -covermode=atomic -coverpkg $(COVER_PKGS) -args -test.gocoverdir="$(PWD)/coverage/unit"
.PHONY: test-with-junit
test-with-junit:
mkdir -p $(JUNIT_OUT_DIR)
$(GO_TOOL) gotestsum \
--packages="./..." --junitfile $(JUNIT_OUT_DIR)/$(CURR_MOD)-junit.xml -- \
$(GOTEST_OPT) ./...
.PHONY: benchmark
benchmark:
MEMBENCH=yes $(GO_TOOL) gotestsum \
--packages="$(ALL_PKGS)" -- \
-bench=. -run=notests ./... | tee benchmark.txt
.PHONY: fmt
fmt: common/gofmt common/goimports common/gofumpt
.PHONY: modernize
modernize:
$(GO_TOOL) modernize \
-fix -test -v -any -fmtappendf -forvar -mapsloop -minmax -newexpr -omitzero -plusbuild \
-rangeint -reflecttypefor -slicescontains -slicessort -stditerators -stringscut \
-stringscutprefix -stringsseq -stringsbuilder -testingcontext -unsafefuncs -waitgroup ./...
.PHONY: tidy
tidy:
rm -fr go.sum
$(GOCMD) mod tidy -compat=1.26.0
.PHONY: lint
lint:
$(GO_TOOL) golangci-lint run
.PHONY: common/gofmt
common/gofmt:
gofmt -w -s ./
.PHONY: common/goimports
common/goimports:
$(GO_TOOL) goimports -w -local go.opentelemetry.io/collector ./
.PHONY: common/gofumpt
common/gofumpt:
$(GO_TOOL) gofumpt -l -w -extra .
.PHONY: vulncheck
vulncheck:
$(GO_TOOL) govulncheck ./...
.PHONY: generate
generate:
$(GOCMD) generate $(shell $(GOCMD) list ./... | grep -v '/internal/metadata')
.PHONY: impi
impi:
$(GO_TOOL) impi \
--local go.opentelemetry.io/collector \
--scheme stdThirdPartyLocal ./...
.PHONY: moddownload
moddownload:
$(GOCMD) mod download
timebenchmark:
go test -bench=. -benchtime=1s ./...
SRC ?= '$(CURDIR)'
FLAGS ?= '-o=$(CURDIR)/'
.PHONY: schemagen
schemagen:
@echo "Running schemagen with filepath='$(SRC)' and flags='$(FLAGS)'"
cd $(SRC_ROOT)/cmd/schemagen && go run . $(FLAGS) $(SRC)
EXTERNAL_PKGS := $(shell go list ./... | grep -v -E '/internal($|/)')
APIDIFF_DATA_DIR ?= internal/data/apidiff
.PHONY: apidiff-build-mod
apidiff-build-mod:
@for pkg in $(EXTERNAL_PKGS); do \
$(SRC_ROOT)/internal/buildscripts/gen-apidiff.sh -p $$pkg -o $(SRC_ROOT)/$(APIDIFF_DATA_DIR) || exit 1; \
done
.PHONY: apidiff-compare-mod
apidiff-compare-mod:
@for pkg in $(EXTERNAL_PKGS); do \
$(SRC_ROOT)/internal/buildscripts/compare-apidiff.sh -p $$pkg -d $(SRC_ROOT)/$(APIDIFF_DATA_DIR) || exit 1; \
done
.PHONY: apidiff-check-mod
apidiff-check-mod:
@for pkg in $(EXTERNAL_PKGS); do \
$(SRC_ROOT)/internal/buildscripts/compare-apidiff.sh -p $$pkg -d $(SRC_ROOT)/$(APIDIFF_DATA_DIR) -c || exit 1; \
done