-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
149 lines (124 loc) · 4.87 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
GO ?= go
GOFMT ?= gofmt "-s"
GOFILES := $(shell find . -name "*.go")
PACKAGES ?= $(shell $(GO) list ./...)
PROJECT_PATH=$(shell cd "$(dirname "$0")"; pwd)
DIR_CONF ?= /etc/pmon3/config
TEST_REGEX := $(or $(TEST_REGEX),"Test")
TEST_FILE_CONFIG ?= $(PROJECT_PATH)/test/e2e/config/test-config.core.yml
TEST_DIR_LOGS=$(shell cat $(TEST_FILE_CONFIG) | grep "directory:" | sed -n "1 p" | cut -d' ' -f4)
TEST_ARTIFACT_PATH=$(shell dirname "$(TEST_DIR_LOGS)")
DEFAULT_TEST_PACKAGES := "pmon3/cli/controller/...,pmon3/cli/output/...,pmon3/cli/shell/,pmon3/conf,pmon3/model/...,pmon3/pmond/controller/...,pmon3/pmond/flap_detector,pmon3/pmond/god,pmon3/pmond/observer,pmon3/pmond/process,pmon3/pmond/repo,pmon3/pmond/shell"
TEST_PACKAGES := $(or $(TEST_PACKAGES),$(DEFAULT_TEST_PACKAGES))
all: help
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: clean
clean: ## remove files created during build pipeline
$(call print-target)
rm -f coverage.*
rm -f '"$(shell go env GOCACHE)/../golangci-lint"'
go clean -i -cache -testcache -fuzzcache -x
rm -rf "$(TEST_ARTIFACT_PATH)"
.PHONY: fmt
fmt: ## format files
$(call print-target)
$(GOFMT) -w $(GOFILES)
.PHONY: lint
lint: ## lint files
$(call print-target)
golangci-lint run --fix
.PHONY: misspell
misspell: ## check for misspellings
$(call print-target)
misspell -error $(GOFILES)
.PHONY: betteralign
betteralign: ## check for better aligned structs
$(call print-target)
betteralign ./...
.PHONY: tools
tools: ## go install tools
$(call print-target)
cd tools && go install $(shell cd tools && $(GO) list -e -f '{{ join .Imports " " }}' -tags=tools)
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
.PHONY: mod
mod: ## go mod tidy
$(call print-target)
go mod tidy
cd tools && go mod tidy
.PHONY: base_build
base_build: mod fmt tools misspell betteralign
cd tools && $(GO) mod tidy
$(ENV_VARS) $(GO) build $(BUILD_FLAGS) -o bin/pmon3 cmd/pmon3/pmon3.go
$(ENV_VARS) $(GO) build $(BUILD_FLAGS) -o bin/pmond cmd/pmond/pmond.go
.PHONY: build
build: ENV_VARS=CGO_ENABLED=0
build: base_build ## run tidy and build with CGO disabled
$(call print-target)
.PHONY: build_cgo
build_cgo: ENV_VARS=CGO_ENABLED=1
build_cgo: base_build ## run tidy and build with CGO enabled
$(call print-target)
.PHONY: test
test: build run_test ## build and run tests with CGO disabled
$(call print-target)
.PHONY: test_cgo
test_cgo: BUILD_FLAGS=$(shell echo '-tags posix_mq,cgo_sqlite')
test_cgo: build_cgo run_test ## build and run tests with CGO enabled
$(call print-target)
.PHONY: test_net
test_net: BUILD_FLAGS=$(shell echo '-tags net')
test_net: build run_test ## build and run tests with net build tag
$(call print-target)
.PHONY: make_test_app
make_test_app: ## build the test app
$(call print-target)
mkdir -p "$(TEST_ARTIFACT_PATH)" || true
cd ./test/app && make build
cp ./test/app/bin/test_app "$(TEST_ARTIFACT_PATH)"
cp ./test/app/bin/test_app "$(TEST_ARTIFACT_PATH)"
.PHONY: run_test
run_test: make_test_app ## run the tests
$(call print-target)
PROJECT_PATH=$(PROJECT_PATH) ARTIFACT_PATH=$(TEST_ARTIFACT_PATH) $(GO) test $(BUILD_FLAGS) -v -run $(TEST_REGEX) -p 1 ./test/e2e/
.PHONY: run_test_cover
run_test_cover: make_test_app ## run the tests and generate a coverage report
$(call print-target)
PROJECT_PATH=$(PROJECT_PATH) ARTIFACT_PATH=$(TEST_ARTIFACT_PATH) $(GO) test $(BUILD_FLAGS) -v -run $(TEST_REGEX) -p 1 -coverprofile=coverage.out -coverpkg=$(TEST_PACKAGES) ./test/e2e/
.PHONY: codecov
codecov: ## process the coverage report and upload it
$(call print-target)
/usr/local/bin/codecov upload-process -t $(CODECOV_TOKEN) -F $(CODECOV_FLAG)
.PHONY: run_test_cover_codecov
run_test_cover_codecov: run_test_cover codecov ## run the tests and process/upload the coverage reports
$(call print-target)
.PHONY: systemd_install
systemd_install: systemd_uninstall install ## install for systemd-based systems
$(call print-target)
cp "$(PROJECT_PATH)/rpm/pmond.service" /usr/lib/systemd/system/
cp "$(PROJECT_PATH)/rpm/pmond.logrotate" /etc/logrotate.d/pmond
mkdir -p $(DIR_CONF)
cp "$(PROJECT_PATH)/config.yml" $(DIR_CONF)
systemctl enable pmond
systemctl start pmond
sh -c "$(PROJECT_PATH)/bin/pmon3 completion bash > /etc/profile.d/pmon3.sh"
$(PROJECT_PATH)/bin/pmon3 ls
$(PROJECT_PATH)/bin/pmon3 --help
.PHONY: systemd_uninstall
systemd_uninstall: ## remove from systemd-based systems
$(call print-target)
rm -rf $(DIR_CONF) /etc/logrotate.d/pmond /etc/profile.d/pmon3.sh
systemctl stop pmond || true
systemctl disable pmond || true
.PHONY: install
install: ## install the binary in the systems executable path
$(call print-target)
cp -R bin/pmon* /usr/local/bin/
.PHONY: protogen
protogen: ## generate the protobufs
$(call print-target)
protoc protos/*.proto --go_out=.
define print-target
@printf "Executing target: \033[36m$@\033[0m\n"
endef