Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·87 lines (67 loc) · 2.17 KB
/
Copy pathMakefile
File metadata and controls
executable file
·87 lines (67 loc) · 2.17 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
BINARY_NAME := rxds
MAIN_PATH := ./cmd/rxds
BUILD_DIR := ./dist
COVERAGE_FILE := coverage.out
GOCMD := go
GOBUILD := $(GOCMD) build
GOCLEAN := $(GOCMD) clean
GOTEST := $(GOCMD) test
GOMOD := $(GOCMD) mod
GOFMT := gofmt
GOVET := $(GOCMD) vet
LDFLAGS := -s -w
BUILD_FLAGS := -trimpath -ldflags "$(LDFLAGS)"
GOLANGCI_LINT := $(shell which golangci-lint 2> /dev/null)
.PHONY: all build debug clean test test-coverage lint-install lint lint-fix security fmt vet tidy check ci help
all: lint test build
build:
@echo "building $(BINARY_NAME)..."
@CGO_ENABLED=0 $(GOBUILD) $(BUILD_FLAGS) -o $(BINARY_NAME) $(MAIN_PATH)
debug:
@echo "building $(BINARY_NAME) (debug, perf-friendly)..."
@$(GOBUILD) -gcflags='all=-N -l' -o $(BINARY_NAME) $(MAIN_PATH)
clean:
@$(GOCLEAN)
@rm -f $(BINARY_NAME)
@rm -rf $(BUILD_DIR)
@rm -f $(COVERAGE_FILE)
test:
@$(GOTEST) -v -race -cover ./...
test-coverage:
@$(GOTEST) -v -race -coverprofile=$(COVERAGE_FILE) -covermode=atomic ./...
@$(GOCMD) tool cover -html=$(COVERAGE_FILE) -o coverage.html
lint-install:
ifndef GOLANGCI_LINT
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin
endif
lint: lint-install
@golangci-lint run --timeout=5m ./...
lint-fix: lint-install
@golangci-lint run --fix --timeout=5m ./...
security: lint-install
@golangci-lint run --disable-all --enable=gosec,bodyclose --timeout=5m ./...
fmt:
@$(GOFMT) -s -w .
@$(GOCMD) fmt ./...
vet:
@$(GOVET) ./...
tidy:
@$(GOMOD) tidy
@$(GOMOD) verify
check: fmt vet lint
ci: tidy fmt vet lint test
help:
@echo "targets:"
@echo " build build the binary (stripped)"
@echo " debug build with full DWARF + no inlining (for perf/pprof)"
@echo " test run tests"
@echo " test-coverage run tests with coverage"
@echo " lint run linters"
@echo " lint-fix run linters with auto-fix"
@echo " security run security linters"
@echo " fmt format code"
@echo " vet run go vet"
@echo " tidy tidy modules"
@echo " check fmt + vet + lint"
@echo " ci full ci check"
@echo " clean clean artifacts"