-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (94 loc) · 3.05 KB
/
Makefile
File metadata and controls
117 lines (94 loc) · 3.05 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
include $(CURDIR)/hack/tools.mk
MAIN_PACKAGE_PATH := ./cmd/z
BINARY_NAME := ./bin/z
VERSION ?= DEV
VERSION_PACKAGE ?= github.com/zkhvan/z/internal/build
# ==========================================================================
# HELPERS
# ==========================================================================
## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
# ==========================================================================
# QUALITY CONTROL
# ==========================================================================
# --------------------------------------------------------------------------
# HELPERS
# --------------------------------------------------------------------------
## tidy: tidy the code
.PHONY: tidy
tidy: tidy-go
## tidy-go: format code and tidy modfile
.PHONY: tidy-go
tidy-go: format-go
go mod tidy -v
## tidy-go-verify: verify go.mod is tidy
.PHONY: tidy-go-verify
tidy-go-verify: tidy-go
git diff --exit-code -- go.mod go.sum || { \
echo "go.mod/go.sum not tidy - run 'go mod tidy'"; \
exit 1; \
}; \
# --------------------------------------------------------------------------
# LINTERS
# --------------------------------------------------------------------------
## lint: lint the code
.PHONY: lint
lint: lint-go
## lint-go: lint the go code
.PHONY: lint-go
lint-go: install-golangci-lint
$(GOLANGCI_LINT) run
## lint-go-fix: lint the go code, auto-fix if possible
.PHONY: lint-go-fix
lint-go-fix:
$(GOLANGCI_LINT) run --fix
# --------------------------------------------------------------------------
# FORMATTERS
# --------------------------------------------------------------------------
.PHONY: format-go
format-go:
go fmt ./...
# ==========================================================================
# DEVELOPMENT
# ==========================================================================
## test: run all tests
.PHONY: test
test:
go test \
-v \
-timeout=300s \
-coverprofile=coverage.out \
-covermode=atomic \
-race \
./...
## test-report: generate a test report
test-report: test
go tool cover -func coverage.out
go tool cover -html coverage.out -o coverage.html
## build: build the application
.PHONY: build
build:
CGO_ENABLED=0 go build \
-ldflags "-w -X $(VERSION_PACKAGE).Version=$(VERSION) -X $(VERSION_PACKAGE).Date=$$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
-o=${BINARY_NAME} \
${MAIN_PACKAGE_PATH}
# ==========================================================================
# CI
#
# These targets are used to run the tests and build the application in CI.
# ==========================================================================
## ci: run automated CI checks
.PHONY: ci
ci: tidy-go-verify test-report build
## ci-deps: install ci dependencies
.PHONY: ci-deps
ci-deps:
sudo apt-get update
sudo apt-get install -y fd-find
# Optionally, create a symlink so you can call it with 'fd'
mkdir -p hack/bin
ln -s $$(which fdfind) hack/bin/fd || true
echo $$(pwd)/hack/bin >> "${GITHUB_PATH}"