podman
77 строк · 2.0 Кб
1GO ?= go
2GOFMT ?= gofmt "-s"
3GO_VERSION=$(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
4PACKAGES ?= $(shell $(GO) list ./...)
5VETPACKAGES ?= $(shell $(GO) list ./... | grep -v /examples/)
6GOFILES := $(shell find . -name "*.go")
7TESTFOLDER := $(shell $(GO) list ./... | grep -E 'gin$$|binding$$|render$$' | grep -v examples)
8TESTTAGS ?= ""
9
10.PHONY: test
11test:
12echo "mode: count" > coverage.out
13for d in $(TESTFOLDER); do \
14$(GO) test $(TESTTAGS) -v -covermode=count -coverprofile=profile.out $$d > tmp.out; \
15cat tmp.out; \
16if grep -q "^--- FAIL" tmp.out; then \
17rm tmp.out; \
18exit 1; \
19elif grep -q "build failed" tmp.out; then \
20rm tmp.out; \
21exit 1; \
22elif grep -q "setup failed" tmp.out; then \
23rm tmp.out; \
24exit 1; \
25fi; \
26if [ -f profile.out ]; then \
27cat profile.out | grep -v "mode:" >> coverage.out; \
28rm profile.out; \
29fi; \
30done
31
32.PHONY: fmt
33fmt:
34$(GOFMT) -w $(GOFILES)
35
36.PHONY: fmt-check
37fmt-check:
38@diff=$$($(GOFMT) -d $(GOFILES)); \
39if [ -n "$$diff" ]; then \
40echo "Please run 'make fmt' and commit the result:"; \
41echo "$${diff}"; \
42exit 1; \
43fi;
44
45vet:
46$(GO) vet $(VETPACKAGES)
47
48.PHONY: lint
49lint:
50@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
51$(GO) get -u golang.org/x/lint/golint; \
52fi
53for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
54
55.PHONY: misspell-check
56misspell-check:
57@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
58$(GO) get -u github.com/client9/misspell/cmd/misspell; \
59fi
60misspell -error $(GOFILES)
61
62.PHONY: misspell
63misspell:
64@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
65$(GO) get -u github.com/client9/misspell/cmd/misspell; \
66fi
67misspell -w $(GOFILES)
68
69.PHONY: tools
70tools:
71@if [ $(GO_VERSION) -gt 15 ]; then \
72$(GO) install golang.org/x/lint/golint@latest; \
73$(GO) install github.com/client9/misspell/cmd/misspell@latest; \
74elif [ $(GO_VERSION) -lt 16 ]; then \
75$(GO) install golang.org/x/lint/golint; \
76$(GO) install github.com/client9/misspell/cmd/misspell; \
77fi
78