-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
82 lines (63 loc) · 2.06 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
.DEFAULT_GOAL := help
SHELL := /bin/bash
GO111MODULE := on
GOPKG += github.com/veraison/cocli/cmd
MOCKGEN := $(shell go env GOPATH)/bin/mockgen
INTERFACES := cmd/isubmitter.go
MOCKPKG := mocks
GOLINT ?= golangci-lint
ifeq ($(MAKECMDGOALS),lint)
GOLINT_ARGS ?= run --timeout=3m
else
ifeq ($(MAKECMDGOALS),lint-extra)
GOLINT_ARGS ?= run --timeout=3m --issues-exit-code=0 -E dupl -E gocritic -E gosimple -E lll -E prealloc
endif
endif
.PHONY: lint lint-extra
lint lint-extra: _mocks; $(GOLINT) $(GOLINT_ARGS)
ifeq ($(MAKECMDGOALS),test)
GOTEST_ARGS ?= -v -race $(GOPKG)
else
ifeq ($(MAKECMDGOALS),test-cover)
GOTEST_ARGS ?= -short -cover $(GOPKG)
endif
endif
COVER_THRESHOLD := $(shell grep '^name: cover' .github/workflows/ci-go-cover.yml | cut -c13-)
define MOCK_template
cmd/mocks/$(notdir $(1)): $(1)
$$(MOCKGEN) -source=$$< -destination=$$@ -package=$$(MOCKPKG)
endef
$(foreach m,$(INTERFACES),$(eval $(call MOCK_template,$(m))))
MOCK_FILES := $(foreach m,$(INTERFACES),$(join cmd/mocks/,$(notdir $(m))))
CLEANFILES := $(MOCK_FILES)
_mocks: $(MOCK_FILES)
.PHONY: _mocks
.PHONY: test test-cover
test test-cover: _mocks; go test $(GOTEST_ARGS)
realtest: _mocks; go test $(GOTEST_ARGS)
.PHONY: realtest
CLEANFILES += cmd/output.cbor
.PHONY: clean
clean: ; $(RM) $(CLEANFILES)
presubmit:
@echo
@echo ">>> Check that the reported coverage figures are $(COVER_THRESHOLD)"
@echo
$(MAKE) test-cover
@echo
@echo ">>> Fix any lint error"
@echo
$(MAKE) lint-extra
.PHONY: licenses
licenses: ; @./scripts/licenses.sh
.PHONY: help
help:
@echo "Available targets:"
@echo " * test: run unit tests for $(GOPKG)"
@echo " * test-cover: run unit tests and measure coverage for $(GOPKG)"
@echo " * lint: lint sources using default configuration"
@echo " * lint-extra: lint sources using default configuration and some extra checkers"
@echo " * presubmit: check you are ready to push your local branch to remote"
@echo " * help: print this menu"
@echo " * licenses: check licenses of dependent packages"
@echo " * clean: remove auto-generated files"