-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
97 lines (77 loc) · 2.25 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
# Go related variables
GO = go
GOFMT = gofmt
GOSTATICCHECK = go run honnef.co/go/tools/cmd/[email protected]
GOMOCKERY = $(GO) run github.com/vektra/mockery/[email protected]
M = $(shell printf "\033[34;1m▶▶▶\033[0m")
# Test coverage files
TEST_COVERAGE_PROFILE_OUTPUT = ".local/coverage.out"
TEST_REPORT_OUTPUT = ".local/test_report.ndjson"
all: verify
.PHONY: verify
verify: tidy checkfmt lint vet build test coverage
# -----------------------------------------------------------------------------
# Build
.PHONY: build
build:
$(info $(M) Building...) @
$(GO) build -o bin/ ./...
.PHONY: cross-build
cross-build:
$(info $(M) Building...) @
./dist.sh
.PHONY: install
install:
$(info $(M) Installing...) @
$(GO) install ./...
# -----------------------------------------------------------------------------
# Test
.PHONY: test
test:
$(info $(M) Running tests...) @
$(GO) test ./...
.PHONY: coverage
coverage:
$(info $(M) Generating coverage information...)
$(eval TEST_COVERAGE_PROFILE_OUTPUT_DIRNAME=$(shell dirname $(TEST_COVERAGE_PROFILE_OUTPUT)))
$(eval TEST_REPORT_OUTPUT_DIRNAME=$(shell dirname $(TEST_REPORT_OUTPUT)))
mkdir -p $(TEST_COVERAGE_PROFILE_OUTPUT_DIRNAME) $(TEST_REPORT_OUTPUT_DIRNAME)
$(GO) test ./... -coverpkg=./... -coverprofile=$(TEST_COVERAGE_PROFILE_OUTPUT) -json > $(TEST_REPORT_OUTPUT)
.PHONY: generate-mocks
generate-mocks:
$(info $(M) Running mockery...)
$(GOMOCKERY)
# ----------------------------------------------------------
# Dependencies
## tidy: Executes a go mod tidy
.PHONY: tidy
tidy:
$(info $(M) Running go mod tidy...) @
$(GO) mod tidy
# ----------------------------------------------------------
# Format and lint
## checkfmt: Check format validation
.PHONY: checkfmt
checkfmt:
$(info $(M) Running gofmt checking code style...)
@fmtRes=$$($(GOFMT) -d .); \
if [ -n "$${fmtRes}" ]; then \
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
echo "Please ensure you are using $$($(GO) version) for formatting code."; \
exit 1; \
fi
## fmt: Formats the code
.PHONY: fmt
fmt:
$(info $(M) Running go fmt...) @
$(GOFMT) -l -w .
## lint: Runs go linter
.PHONY: lint
lint:
$(info $(M) Running lints...)
$(GOSTATICCHECK) ./...
## vet: Run go vet
.PHONY: vet
vet:
$(info $(M) Running go vet...)
$(GO) vet ./...