-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (71 loc) · 2.2 KB
/
Copy pathMakefile
File metadata and controls
91 lines (71 loc) · 2.2 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
MODULE_NAME=httpmock
GOLANGCI_LINT_VERSION ?= v2.13.0
MOCKERY_VERSION ?= v3.7.4
GO ?= go
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
MOCKERY ?= $(shell $(GO) env GOPATH)/bin/mockery-$(MOCKERY_VERSION)
VENDOR_DIR = vendor
GOROOT_DIR = $(shell $(GO) env GOROOT)
GITHUB_OUTPUT ?= /dev/null
# Other config
NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m
ifeq ($(V),1)
Q = @set -x;
else
Q = @
endif
.PHONY: $(VENDOR_DIR)
$(VENDOR_DIR):
$(Q)mkdir -p $(VENDOR_DIR)
$(Q)$(GO) mod vendor
$(Q)$(GO) mod tidy
.PHONY: bump-deps
bump-deps:
$(Q)$(GO) get -u ./...
.PHONY: tidy
tidy:
$(Q)$(GO) mod tidy
.PHONY: lint
ifeq ($(V),1)
GOLANGCI_LINT_FLAGS = -vvvv
else
GOLANGCI_LINT_FLAGS =
endif
lint: $(GOLANGCI_LINT)
@printf -- "$(OK_COLOR)==> lint$(NO_COLOR)\n"
$(Q)GOROOT=$(GOROOT_DIR) PATH="$(GOROOT_DIR)/bin:$$PATH" $(GOLANGCI_LINT) run -c .golangci.yaml --color always $(GOLANGCI_LINT_FLAGS)
.PHONY: test
test: test-unit
## Run unit tests
.PHONY: test-unit
test-unit:
@printf -- "$(OK_COLOR)==> unit test$(NO_COLOR)\n"
$(Q)$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic -race ./...
.PHONY: gen
gen: gen-mocks
.PHONY: gen-mocks
gen-mocks: $(MOCKERY)
@printf -- "$(OK_COLOR)==> generate mocks$(NO_COLOR)\n"
$(Q)GOROOT=$(GOROOT_DIR) PATH="$(GOROOT_DIR)/bin:$$PATH" $(MOCKERY) --config .mockery.yaml
.PHONY: $(GITHUB_OUTPUT)
$(GITHUB_OUTPUT):
@echo "MODULE_NAME=$(MODULE_NAME)" >> "$@"
@echo "GOLANGCI_LINT_VERSION=$(GOLANGCI_LINT_VERSION)" >> "$@"
$(GOLANGCI_LINT):
@printf -- "$(OK_COLOR)==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)$(NO_COLOR)\n"
$(Q)curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b /tmp "$(GOLANGCI_LINT_VERSION)"
$(Q)$(call install-dep,/tmp/golangci-lint,$(GOLANGCI_LINT))
$(MOCKERY):
@printf -- "$(OK_COLOR)==> Installing mockery $(MOCKERY_VERSION)$(NO_COLOR)\n"
$(Q)GOBIN=/tmp $(GO) install github.com/vektra/mockery/$(shell echo "$(MOCKERY_VERSION)" | cut -d '.' -f 1)@$(MOCKERY_VERSION)
$(Q)$(call install-dep,/tmp/mockery,$(MOCKERY))
define install-dep
if [ "$(1)" != "$(2)" ]; then \
mkdir -p $$(dirname $(2)) || true; \
mv $(1) $(2); \
fi
chmod +x "$(2)"
endef