-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile.Common
75 lines (61 loc) · 2.19 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
# In order to ensure make instructions fail if there is command that fails a pipe (ie: `go test ... | tee -a ./test_results.txt`)
# the value `-o pipefail` (or `set -o pipefail`) is added to each shell command that make runs
# otherwise in the example command pipe, only the exit code of `tee` is recorded instead of `go test` which can cause
# test to pass in CI when they should not.
SHELL = /bin/bash
ifeq ($(shell uname -s),Windows)
.SHELLFLAGS = /o pipefile /c
else
.SHELLFLAGS = -o pipefail -c
endif
# SRC_ROOT is the top of the source tree.
SRC_ROOT := $(shell git rev-parse --show-toplevel)
# A lot of the following install tools commands were leveraged from the
# Open Telemetry Contributor Makefile following the Go Paradigm for Third Party Tools
# See https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/Makefile.Common#L39-L74 for more details.
TOOLS_MOD_DIR := $(SRC_ROOT)/internal/tools
TOOLS_BIN_DIR := $(SRC_ROOT)/.tools
TOOLS_MOD_REGEX := "\s+_\s+\".*\""
TOOLS_PKG_NAMES := $(shell grep -E $(TOOLS_MOD_REGEX) < $(TOOLS_MOD_DIR)/tools.go | tr -d " _\"")
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(TOOLS_PKG_NAMES)))
.PHONY: install-tools
install-tools: $(TOOLS_BIN_NAMES)
.PHONY: clean
clean:
rm -rf $(TOOLS_BIN_DIR)
$(TOOLS_BIN_DIR):
mkdir -p $@
$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod
cd $(TOOLS_MOD_DIR) && go build -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES))
LINT := $(TOOLS_BIN_DIR)/golangci-lint
GOIMPORTS := $(TOOLS_BIN_DIR)/goimports
PORTO := $(TOOLS_BIN_DIR)/porto
GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck
GENQLIENT := $(TOOLS_BIN_DIR)/genqlient
SEC := $(TOOLS_BIN_DIR)/gosec
STATICCHECK := $(TOOLS_BIN_DIR)/staticcheck
MDATAGEN := $(TOOLS_BIN_DIR)/mdatagen
OCB := $(TOOLS_BIN_DIR)/builder
GORELEASER := $(TOOLS_BIN_DIR)/goreleaser
MULTIMOD := $(TOOLS_BIN_DIR)/multimod
CROSSLINK := $(TOOLS_BIN_DIR)/crosslink
OSV := $(TOOLS_BIN_DIR)/osv-scanner
.PHONY: lint
lint:
$(LINT) run
.PHONY: tidy
tidy:
-rm go.sum
go mod tidy -compat=1.23
.PHONY: gen
gen:
go generate ./...
.PHONY: test
test:
go test -v ./... -coverprofile=coverage.out -covermode=atomic
.PHONY: fmt
fmt:
go fmt ./...
.PHONY: scan
scan:
$(OSV) -r .