-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (79 loc) · 2.8 KB
/
Makefile
File metadata and controls
102 lines (79 loc) · 2.8 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
.PHONY: default
default: build lint test
.PHONY: build
build:
go build ./...
GOLANG_TOOL_PATH_TO_BIN=$(shell go env GOPATH)
GOLANGCI_LINT_CLI_VERSION?=latest
GOLANGCI_LINT_CLI_MODULE=github.com/golangci/golangci-lint/cmd/golangci-lint
GOLANGCI_LINT_CLI=$(GOLANG_TOOL_PATH_TO_BIN)/bin/golangci-lint
$(GOLANGCI_LINT_CLI):
$(MAKE) golangci-lint-cli-install
golangci-lint-cli-install:
go install $(GOLANGCI_LINT_CLI_MODULE)@$(GOLANGCI_LINT_CLI_VERSION)
.PHONY: lint
lint: $(GOLANGCI_LINT_CLI)
golangci-lint run
GODOC_CLI_VERSION=latest
GODOC_CLI_MODULE=golang.org/x/tools/cmd/godoc
GODOC_CLI=$(GOLANG_TOOL_PATH_TO_BIN)/bin/godoc
$(GODOC_CLI):
$(MAKE) godoc-cli-install
godoc-cli-install:
go install $(GODOC_CLI_MODULE)@$(GODOC_CLI_VERSION)
.PHONY: godoc
godoc: $(GODOC_CLI)
@echo "Open http://localhost:6060/pkg/github.com/akm/sql-slog"
godoc -http=:6060
# examples-logs-gen
examples-%:
$(MAKE) -C examples $*
tests-%:
$(MAKE) -C tests $*
GO_TEST_OPTIONS?=
.PHONY: test
test: test-unit tests-run
.PHONY: test-unit
test-unit:
go test $(GO_TEST_OPTIONS) ./...
GO_COVERAGE_DIR=coverage/unit
$(GO_COVERAGE_DIR):
mkdir -p $(GO_COVERAGE_DIR)
GO_COVERAGE_MERGED_DIR=coverage/merged
$(GO_COVERAGE_MERGED_DIR):
mkdir -p $(GO_COVERAGE_MERGED_DIR)
GO_COVERAGE_HTML?=coverage.html
GO_COVERAGE_PROFILE?=coverage.txt
$(GO_COVERAGE_PROFILE):
$(MAKE) test-coverage-profile
test-with-coverage: test-with-coverage-unit tests-run-with-coverage
# See https://app.codecov.io/github/akm/go-requestid/new
.PHONY: test-with-coverage-unit
test-with-coverage-unit: $(GO_COVERAGE_DIR)
go test -cover ./... -args -test.gocoverdir="$(GO_COVERAGE_DIR)"
.PHONY: test-coverage-profile
test-coverage-profile: $(GO_COVERAGE_DIR) $(GO_COVERAGE_MERGED_DIR)
go tool covdata merge \
-i $(GO_COVERAGE_DIR),tests/mysql/coverage/unit,tests/postgres/coverage/unit,tests/sqlite3/coverage/unit \
-o $(GO_COVERAGE_MERGED_DIR)
go tool covdata percent -i=$(GO_COVERAGE_MERGED_DIR) -o $(GO_COVERAGE_PROFILE)
.PHONY: test-coverage
test-coverage: test-coverage-profile
go tool cover -html=$(GO_COVERAGE_PROFILE) -o $(GO_COVERAGE_HTML)
@command -v open && open $(GO_COVERAGE_HTML) || echo "open $(GO_COVERAGE_HTML)"
.PHONY: linters-enabled
linters-enabled:
@golangci-lint linters | awk '/^Enabled by your configuration linters:$$/{flag=1;next}/^Disabled by your configuration linters:$$/{flag=0}flag{print}'
METADATA_YAML=.project.yaml
$(METADATA_YAML): metadata-gen
METADATA_LINTERS=$(strip $(shell $(MAKE) linters-enabled --no-print-directory 2>/dev/null | grep . | wc -l))
.PHONY: metadata-gen
metadata-gen:
@echo "linters: $(METADATA_LINTERS)" > $(METADATA_YAML)
.PHONY: clean
clean: tests-clean examples-clean
rm -rf coverage
rm -f $(GO_COVERAGE_HTML) $(GO_COVERAGE_PROFILE)
.PHONY: clobber
clobber: tests-clobber examples-clobber clean
rm -f $(METADATA_YAML)