-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (94 loc) · 4.04 KB
/
Makefile
File metadata and controls
111 lines (94 loc) · 4.04 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
# Set up GOBIN so that our binaries are installed to ./bin instead of $GOPATH/bin.
PROJECT_ROOT = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
export GOBIN = $(PROJECT_ROOT)/bin
GOLANGCI_LINT_VERSION := $(shell $(GOBIN)/golangci-lint version --short 2>/dev/null)
REQUIRED_GOLANGCI_LINT_VERSION := $(shell cat .golangci.version)
# Directories containing independent Go modules.
MODULE_DIRS = . ./tools
.PHONY: all
all: build lint test integration-test
.PHONY: clean
clean:
@rm -rf $(GOBIN)
.PHONY: build
build:
go install go.uber.org/nilaway/cmd/nilaway
.PHONY: test
test:
@$(foreach mod,$(MODULE_DIRS),(cd $(mod) && go test -race ./...) &&) true
.PHONY: cover
cover:
@$(foreach mod,$(MODULE_DIRS), ( \
cd $(mod) && \
go test -race -coverprofile=cover.out -coverpkg=./... ./... \
&& go tool cover -html=cover.out -o cover.html) &&) true
.PHONY: upgrade-deps
upgrade-deps: MODULE_DIRS := $(MODULE_DIRS) ./testdata/integration
upgrade-deps:
@echo "[upgrade-deps] Upgrading dependencies and tools"
@echo "[upgrade-deps] Checking for latest golangci-lint version"
@CURRENT_VERSION=$$(cat .golangci.version); \
LATEST_VERSION=$$(curl -s https://api.github.com/repos/golangci/golangci-lint/releases/latest | grep '"tag_name"' | sed 's/.*"v\([^"]*\)".*/\1/'); \
echo "[upgrade-deps] Current golangci-lint version: $$CURRENT_VERSION"; \
echo "[upgrade-deps] Latest golangci-lint version: $$LATEST_VERSION"; \
if [ "$$CURRENT_VERSION" != "$$LATEST_VERSION" ]; then \
echo "[upgrade-deps] Updating .golangci.version from $$CURRENT_VERSION to $$LATEST_VERSION"; \
printf "$$LATEST_VERSION" > .golangci.version; \
else \
echo "[upgrade-deps] golangci-lint already up to date"; \
fi
@echo "[upgrade-deps] Upgrading dependencies in all modules: $(MODULE_DIRS)"
@$(foreach mod,$(MODULE_DIRS), \
(cd $(mod) && \
$(if $(GO_VERSION),echo "[upgrade-deps] go mod edit -go=$(GO_VERSION): $(mod)" && go mod edit -go=$(GO_VERSION) &&) \
echo "[upgrade-deps] go get -u ./...: $(mod)" && \
go get -u ./... && \
echo "[upgrade-deps] go mod tidy: $(mod)" && \
go mod tidy) &&) true
.PHONY: golden-test
golden-test:
@cd tools && go install go.uber.org/nilaway/tools/cmd/golden-test
@$(GOBIN)/golden-test $(ARGS)
.PHONY: integration-test
integration-test:
@cd tools && go install go.uber.org/nilaway/tools/cmd/integration-test
@$(GOBIN)/integration-test
.PHONY: lint
lint: format-lint tidy-lint golangci-lint nilaway-lint
@echo "Run \`make lint-fix\` to automatically apply fixes (if available)"
.PHONY: lint-fix
lint-fix: export FIX=true
lint-fix: format-lint tidy-lint golangci-lint nilaway-lint
# Install golangci-lint with the required version in GOBIN if it is not already installed.
.PHONY: install-golangci-lint
install-golangci-lint:
ifneq ($(GOLANGCI_LINT_VERSION),$(REQUIRED_GOLANGCI_LINT_VERSION))
@echo "[lint] installing golangci-lint v$(REQUIRED_GOLANGCI_LINT_VERSION) since current version is \"$(GOLANGCI_LINT_VERSION)\""
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v$(REQUIRED_GOLANGCI_LINT_VERSION)
endif
@echo "[lint] $(shell $(GOBIN)/golangci-lint version)"
.PHONY: format-lint
format-lint: install-golangci-lint
@$(foreach mod,$(MODULE_DIRS), \
(cd $(mod) && \
echo "[lint] golangci-lint fmt: $(mod)" && \
$(GOBIN)/golangci-lint fmt $(if $(FIX),,--diff)) &&) true
.PHONY: golangci-lint
golangci-lint: install-golangci-lint
@$(foreach mod,$(MODULE_DIRS), \
(cd $(mod) && \
echo "[lint] golangci-lint: $(mod)" && \
$(GOBIN)/golangci-lint run $(if $(FIX),--fix) --path-prefix $(mod)) &&) true
.PHONY: tidy-lint
tidy-lint:
@$(foreach mod,$(MODULE_DIRS), \
(cd $(mod) && \
echo "[lint] mod tidy: $(mod)" && \
go mod tidy $(if $(FIX),,-diff)) &&) true
.PHONY: nilaway-lint
nilaway-lint: build
# Enable -experimental-struct-init for linting nilaway (tracked in #23).
@$(foreach mod,$(MODULE_DIRS), \
(cd $(mod) && \
echo "[lint] nilaway linting itself: $(mod)" && \
$(GOBIN)/nilaway -include-pkgs="go.uber.org/nilaway" -experimental-anonymous-function ./...) &&) true