-
Notifications
You must be signed in to change notification settings - Fork 75
/
GNUmakefile
107 lines (85 loc) · 3.25 KB
/
GNUmakefile
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
TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=signalfx
SRC_ROOT := $(shell git rev-parse --show-toplevel)
SRC_GO_FILES := $(shell find $(SRC_ROOT) -name '*.go')
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 " _\"" | grep -vE '/v[0-9]+$$')
TOOLS_BIN_NAMES := $(addprefix $(TOOLS_BIN_DIR)/, $(notdir $(shell echo $(TOOLS_PKG_NAMES))))
ADDLICENCESE := $(TOOLS_BIN_DIR)/addlicense
GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
default: build
.PHONY: install-tools
install-tools: $(TOOLS_BIN_NAMES)
$(TOOLS_BIN_DIR):
mkdir -p $@
$(TOOLS_BIN_NAMES): $(TOOLS_BIN_DIR) $(TOOLS_MOD_DIR)/go.mod
go -C $(TOOLS_MOD_DIR) build -o $@ -trimpath $(filter %/$(notdir $@),$(TOOLS_PKG_NAMES))
.PHONY: addlicense
addlicense: $(ADDLICENCESE)
@ADDLICENCESEOUT=`$(ADDLICENCESE) -y "" -c 'Splunk, Inc.' -l mpl -s=only $(SRC_GO_FILES) 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: $(ADDLICENCESE)
@ADDLICENCESEOUT=`$(ADDLICENCESE) -check $(SRC_GO_FILES) 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: govulncheck
govulncheck: $(GOVULNCHECK)
$(GOVULNCHECK)
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v
.PHONY: lint-fix
lint-fix:
$(GOLANGCI_LINT) run -v --fix
build:
go build
test:
go test --cover --race -v --timeout 30s ./...
test-with-cover:
mkdir -p $(PWD)/coverage/unit || true
go test --race --timeout 300s --cover ./... \
-covermode=atomic \
-args -test.gocoverdir="$(PWD)/coverage/unit"
go tool covdata textfmt -i=./coverage/unit -o ./coverage.txt
testacc:
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m
fmt:
gofmt -w $(GOFMT_FILES)
test-compile:
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./$(PKG_NAME)"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)
website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile website website-test