Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
126 lines (108 loc) · 4.85 KB
/
Copy pathMakefile
File metadata and controls
126 lines (108 loc) · 4.85 KB
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
# =============================================================================
# darkit/slog — Makefile
# =============================================================================
.PHONY: all build vet test lint fmt cover release clean help
# Go parameters
GOCMD = go
GOBUILD = $(GOCMD) build
GOTEST = $(GOCMD) test
GOVET = $(GOCMD) vet
GOFMT = $(GOCMD) fmt
GOMOD = $(GOCMD) mod
BIN_DIR = bin
LDFLAGS = -s -w
# =============================================================================
## all: Default — build + vet + test
# =============================================================================
all: build vet test
# =============================================================================
## build: Compile all packages
# =============================================================================
build:
$(GOBUILD) -v ./...
# =============================================================================
## build-install: Build and install binary to $(BIN_DIR)
# =============================================================================
build-install:
@mkdir -p $(BIN_DIR)
$(GOBUILD) -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/slog ./...
# =============================================================================
## vet: Run go vet
# =============================================================================
vet:
$(GOVET) ./...
# =============================================================================
## test: Run all tests
# =============================================================================
test:
$(GOTEST) -count=1 ./...
# =============================================================================
## test-race: Run all tests with race detector
# =============================================================================
test-race:
$(GOTEST) -race -count=1 ./...
# =============================================================================
## test-verbose: Run all tests with verbose output
# =============================================================================
test-verbose:
$(GOTEST) -v -count=1 ./...
# =============================================================================
## test-short: Run only short tests
# =============================================================================
test-short:
$(GOTEST) -short -count=1 ./...
# =============================================================================
## test-bench: Run benchmarks
# =============================================================================
test-bench:
$(GOTEST) -bench=. -benchmem -count=1 ./...
# =============================================================================
## test-coverage: Run tests and generate coverage report
# =============================================================================
test-coverage:
$(GOTEST) -race -covermode atomic -coverprofile=coverage.out ./...
$(GOCMD) tool cover -func=coverage.out
@echo
@echo "HTML coverage report: coverage.html"
$(GOCMD) tool cover -html=coverage.out -o coverage.html
# =============================================================================
## lint: Run golangci-lint
# =============================================================================
lint:
golangci-lint run ./...
# =============================================================================
## lint-fix: Run golangci-lint with auto-fix
# =============================================================================
lint-fix:
golangci-lint run --fix ./...
# =============================================================================
## fmt: Run gofmt + goimports
# =============================================================================
fmt:
$(GOFMT) ./...
@command -v goimports >/dev/null 2>&1 && goimports -local github.com/darkit/slog -w . || true
# =============================================================================
## tidy: Tidy and verify module dependencies
# =============================================================================
tidy:
$(GOMOD) tidy
$(GOMOD) verify
# =============================================================================
## clean: Remove build artifacts and coverage files
# =============================================================================
clean:
rm -rf $(BIN_DIR) coverage.out coverage.html
find . -name "*.test" -delete -o -name "*.prof" -delete
# =============================================================================
## release-dry: Dry-run goreleaser
# =============================================================================
release-dry:
goreleaser release --snapshot --clean
# =============================================================================
## help: Print this help message
# =============================================================================
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'