generated from mccutchen/go-pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
97 lines (78 loc) · 2.94 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
# Default flags used by the test, testci, testcover targets
COVERAGE_PATH ?= coverage.out
COVERAGE_ARGS ?= -covermode=atomic -coverprofile=$(COVERAGE_PATH)
TEST_ARGS ?= -race -count=1 -timeout=10s
AUTOBAHN_ARGS ?= -race -count=1 -timeout=120s
BENCH_COUNT ?= 10
BENCH_ARGS ?= -bench=. -benchmem -count=$(BENCH_COUNT) -run=^$$
DOCS_PORT ?= :8080
# 3rd party tools
CMD_GOFUMPT := go run mvdan.cc/[email protected]
CMD_PKGSITE := go run golang.org/x/pkgsite/cmd/pkgsite@latest
CMD_REVIVE := go run github.com/mgechev/[email protected]
CMD_STATICCHECK := go run honnef.co/go/tools/cmd/[email protected]
# Find examples to build
OUT_DIR ?= out
OUT_DIR_ABS := $(abspath $(OUT_DIR))
EXAMPLE_DIR := examples
EXAMPLE_NAMES := $(shell ls $(EXAMPLE_DIR))
EXAMPLE_PATHS := $(addprefix $(OUT_DIR)/,$(EXAMPLE_NAMES)) # -> $(OUT_DIR)/foo $(OUT_DIR)/bar
# ===========================================================================
# Tests
# ===========================================================================
test:
go test $(TEST_ARGS) ./...
.PHONY: test
# Test command to run for continuous integration, which includes code coverage
# based on codecov.io's documentation:
# https://github.com/codecov/example-go/blob/b85638743b972bd0bd2af63421fe513c6f968930/README.md
testci:
go test $(TEST_ARGS) $(COVERAGE_ARGS) ./...
.PHONY: testci
testcover: testci
go tool cover -html=$(COVERAGE_PATH)
.PHONY: testcover
# Run the autobahn fuzzingclient test suite (requires docker running locally).
#
# See "Autobahn integration tests" in the README for documentation on how to
# configure these tests.
testautobahn:
AUTOBAHN=1 go test -run ^TestAutobahn$$ $(AUTOBAHN_ARGS) ./...
.PHONY: testautobahn
# ===========================================================================
# Benchmarks
# ===========================================================================
bench:
go test $(BENCH_ARGS)
.PHONY: bench
# ===========================================================================
# Linting/formatting
# ===========================================================================
lint:
test -z "$$($(CMD_GOFUMPT) -d -e .)" || (echo "Error: gofmt failed"; $(CMD_GOFUMPT) -d -e . ; exit 1)
go vet ./...
$(CMD_REVIVE) -set_exit_status ./...
$(CMD_STATICCHECK) ./...
.PHONY: lint
fmt:
$(CMD_GOFUMPT) -d -e -w .
.PHONY: fmt
docs:
$(CMD_PKGSITE) -http $(DOCS_PORT)
# ===========================================================================
# Example binaries
# ===========================================================================
# Build every example we found
examples: $(EXAMPLE_PATHS)
.PHONY: examples
# Build a specific example
$(OUT_DIR)/%: force-rebuild
@mkdir -p $(OUT_DIR)
@echo "Building $@"
cd $(EXAMPLE_DIR)/$* && CGO_ENABLED=0 go build $(BUILD_ARGS) -o $(abspath $(OUT_DIR))/$*
# phony target used to always rebuild the example binaries
.PHONY: force-rebuild
force-rebuild:
clean:
rm -rf $(OUT_DIR) $(COVERAGE_PATH)
.PHONY: clean