-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
99 lines (78 loc) · 2.44 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
98
99
SHELL = /bin/bash
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# Setting GOBIN and PATH ensures two things:
# - All 'go install' commands we run
# only affect the current directory.
# - All installed tools are available on PATH
# for commands like go generate.
export GOBIN = $(PROJECT_ROOT)/bin
export PATH := $(GOBIN):$(PATH)
GO_MODULES ?= $(shell find . \
-path '*/.*' -prune -o \
-type f -a -name 'go.mod' -print | xargs -n1 dirname)
TEST_FLAGS ?= -race
# Non-test Go files.
GO_SRC_FILES = $(shell find . \
-path '*/.*' -prune -o \
'(' -type f -a -name '*.go' -a -not -name '*_test.go' ')' -print)
TMUX_FASTCOPY = bin/tmux-fastcopy
MOCKGEN = bin/mockgen
.PHONY: all
all: build lint test
.PHONY: build
build: $(TMUX_FASTCOPY)
$(TMUX_FASTCOPY): $(GO_SRC_FILES)
go install github.com/abhinav/tmux-fastcopy
.PHONY: generate
generate: $(MOCKGEN)
go generate -x ./...
$(MOCKGEN): go.mod
go install github.com/golang/mock/mockgen
.PHONY: test
test:
go test $(TEST_FLAGS) ./...
.PHONY: test-integration
test-integration: $(TMUX_FASTCOPY)
go test -C integration $(TEST_FLAGS) ./...
.PHONY: cover
cover: export GOEXPERIMENT = coverageredesign
cover:
go test $(TEST_FLAGS) -coverprofile=cover.out -coverpkg=./... ./...
go tool cover -html=cover.out -o cover.html
.PHONY: cover-integration
cover-integration: export GOEXPERIMENT = coverageredesign
cover-integration:
$(eval BIN := $(shell mktemp -d))
$(eval COVERDIR := $(shell mktemp -d))
GOBIN=$(BIN) \
go install -cover -coverpkg=./... github.com/abhinav/tmux-fastcopy
GOCOVERDIR=$(COVERDIR) PATH=$(BIN):$$PATH \
go test -C integration $(TEST_FLAGS) ./...
go tool covdata textfmt -i=$(COVERDIR) -o=cover.integration.out
go tool cover -html=cover.integration.out -o cover.integration.html
.PHONY: lint
lint: golangci-lint tidy-lint generate-lint
.PHONY: fmt
fmt:
gofumpt -w .
.PHONY: golangci-lint
golangci-lint:
$(foreach mod,$(GO_MODULES), \
(cd $(mod) && golangci-lint run --path-prefix $(mod)) &&) true
.PHONY: tidy
tidy:
$(foreach mod,$(GO_MODULES),(cd $(mod) && go mod tidy) &&) true
.PHONY: tidy-lint
tidy-lint:
$(foreach mod,$(GO_MODULES), \
(cd $(mod) && go mod tidy && \
git diff --exit-code -- go.mod go.sum || \
(echo "[$(mod)] go mod tidy changed files" && false)) &&) true
.PHONY: generate-lint
generate-lint:
make generate
@if ! git diff --quiet; then \
echo "working tree is dirty after generate:" && \
git status --porcelain && \
false; \
fi