-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
139 lines (100 loc) · 4.12 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
SHELL := /bin/bash
.PHONY: default clean build build-tests fmt lint vet cyclo ineffassign shellcheck errcheck goconst gosec abcgo style run test test-postgres cover integration_tests rest_api_tests sqlite_db license before_commit bdd_tests help godoc install_docgo install_addlicense
SOURCES:=$(shell find . -name '*.go')
BINARY:=ccx-notification-service
DOCFILES:=$(addprefix docs/packages/, $(addsuffix .html, $(basename ${SOURCES})))
default: build
clean: ## Run go clean
@go clean
build: ${BINARY} ## Build binary containing service executable
build-cover: ${SOURCES} ## Build binary with code coverage detection support
./build.sh -cover
${BINARY}: ${SOURCES}
./build.sh
fmt: ## Run go fmt -w for all sources
@echo "Running go formatting"
./gofmt.sh
lint: ## Run golint
@echo "Running go lint"
./golint.sh
vet: ## Run go vet. Report likely mistakes in source code
@echo "Running go vet"
./govet.sh
cyclo: ## Run gocyclo
@echo "Running gocyclo"
./gocyclo.sh
ineffassign: ## Run ineffassign checker
@echo "Running ineffassign checker"
./ineffassign.sh
shellcheck: ## Run shellcheck
./shellcheck.sh
errcheck: ## Run errcheck
@echo "Running errcheck"
./goerrcheck.sh
goconst: ## Run goconst checker
@echo "Running goconst checker"
./goconst.sh ${VERBOSE}
gosec: ## Run gosec checker
@echo "Running gosec checker"
./gosec.sh ${VERBOSE}
abcgo: ## Run ABC metrics checker
@echo "Run ABC metrics checker"
./abcgo.sh ${VERBOSE}
style: fmt vet lint cyclo shellcheck errcheck goconst gosec ineffassign abcgo ## Run all the formatting related commands (fmt, vet, lint, cyclo) + check shell scripts
run: ${BINARY} ## Build the project and executes the binary
./$^
gen-mocks: ## Generates the mocks using mockery. Needs go >= 1.18
go install github.com/vektra/mockery/v2@latest
mockery --all --output tests/mocks
test: ${BINARY} ## Run the unit tests
./unit-tests.sh
build-test: gen-mocks ## Build native binary with unit tests and benchmarks
go test -c
profiler: ${BINARY} ## Run the unit tests with profiler enabled
./profile.sh
benchmark.txt: benchmark
benchmark: ${BINARY} ## Run benchmarks
go test -bench=. -run ^$ -v `go list ./... | grep -v tests | tr '\n' ' '` | tee benchmark.txt
# go test -bench=. -run=^$ | tee benchmark.txt
benchmark.csv: benchmark.txt ## Export benchmark results into CSV
awk '/Benchmark/{count ++; gsub(/BenchmarkTest/,""); printf("%d,%s,%s,%s\n",count,$$1,$$2,$$3)}' $< > $@
cover: test ## Generate HTML pages with code coverage
@go tool cover -html=coverage.out
coverage: ## Display code coverage on terminal
@go tool cover -func=coverage.out
license: install_addlicense
addlicense -c "Red Hat, Inc" -l "apache" -ignore "docs/**" -v ./
bdd_tests: ## Run BDD tests (needs real dependencies)
@echo "Run BDD tests with real dependencies"
cp ./config-devel.toml bdd_tests/config.toml
pushd bdd_tests/ && ./run_tests.sh && popd
bdd_tests_mock: ## Run BDD tests with mocked dependencies
@echo "Run BDD tests with mocked dependencies"
cp ./config-devel.toml bdd_tests/config.toml
pushd bdd_tests/ && WITHMOCK=1 ./run_tests.sh && popd
before_commit: style test test-postgres integration_tests license ## Checks done before commit
./check_coverage.sh
help: ## Show this help screen
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ''
function_list: ${BINARY} ## List all functions in generated binary file
go tool objdump ${BINARY} | grep ^TEXT | sed "s/^TEXT\s//g"
docs/packages/%.html: %.go
mkdir -p $(dir $@)
docgo -outdir $(dir $@) $^
addlicense -c "Red Hat, Inc" -l "apache" -v $@
godoc: export GO111MODULE=off
godoc: install_docgo install_addlicense ${DOCFILES} docs/sources.md
docs/sources.md: docs/sources.tmpl.md ${DOCFILES}
./gen_sources_md.sh
install_docgo: export GO111MODULE=off
install_docgo:
[[ `command -v docgo` ]] || go get -u github.com/dhconnelly/docgo
install_addlicense: export GO111MODULE=off
install_addlicense:
[[ `command -v addlicense` ]] || GO111MODULE=off go get -u github.com/google/addlicense