-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathMakefile
122 lines (92 loc) · 3.14 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
EXECUTABLE ?= telescopes
IMAGE ?= banzaicloud/$(EXECUTABLE)
TAG ?= dev-$(shell git log -1 --pretty=format:"%h")
LD_FLAGS = -X "main.version=$(TAG)"
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
PKGS=$(shell go list ./... | grep -v /vendor)
SWAGGER_PI_TMP_FILE = ./docs/openapi/productinfo.json
SWAGGER_PI_FILE = ./docs/openapi/productinfo.yaml
SWAGGER_REC_TMP_FILE = ./docs/openapi/recommender.json
SWAGGER_REC_FILE = ./docs/openapi/recommender.yaml
.PHONY: _no-target-specified
_no-target-specified:
$(error Please specify the target to make - `make list` shows targets.)
.PHONY: list
list:
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
all: clean deps fmt vet docker push
clean:
go clean -i ./...
deps-swagger:
ifeq ($(shell which swagger),)
go get -u github.com/go-swagger/go-swagger/cmd/swagger
endif
ifeq ($(shell which swagger2openapi),)
npm install -g swagger2openapi
endif
deps: deps-swagger
go get ./...
fmt:
@gofmt -w ${GOFILES_NOVENDOR}
vet:
@go vet -composites=false ./...
docker:
docker build --rm -t $(IMAGE):$(TAG) .
push:
docker push $(IMAGE):$(TAG)
run-dev:
. .env
go run $(wildcard *.go)
swagger:
swagger generate spec -m -b ./cmd/productinfo -o $(SWAGGER_PI_TMP_FILE)
swagger2openapi -y $(SWAGGER_PI_TMP_FILE) > $(SWAGGER_PI_FILE)
swagger generate spec -m -b ./cmd/telescopes -o $(SWAGGER_REC_TMP_FILE)
swagger2openapi -y $(SWAGGER_REC_TMP_FILE) > $(SWAGGER_REC_FILE)
generate-pi-client:
swagger generate client -f ./docs/openapi/productinfo.json -A productinfo -t pkg/productinfo-client/
build:
go build ./cmd/telescopes/
go build ./cmd/productinfo/
build-all: check-fmt check-misspell lint vet test swagger build
check-fmt:
PKGS="${GOFILES_NOVENDOR}" GOFMT="gofmt" ./scripts/fmt-check.sh
check-misspell: install-misspell
PKGS="${GOFILES_NOVENDOR}" MISSPELL="misspell" ./scripts/misspell-check.sh
misspell: install-misspell
misspell -w ${GOFILES_NOVENDOR}
lint: install-golint
golint -min_confidence 0.9 -set_exit_status $(PKGS)
test:
@go test -v -cover ./... > test.txt
install-golint:
GOLINT_CMD=$(shell command -v golint 2> /dev/null)
ifndef GOLINT_CMD
go get github.com/golang/lint/golint
endif
install-misspell:
MISSPELL_CMD=$(shell command -v misspell 2> /dev/null)
ifndef MISSPELL_CMD
go get -u github.com/client9/misspell/cmd/misspell
endif
install-ineffassign:
INEFFASSIGN_CMD=$(shell command -v ineffassign 2> /dev/null)
ifndef INEFFASSIGN_CMD
go get -u github.com/gordonklaus/ineffassign
endif
install-gocyclo:
GOCYCLO_CMD=$(shell command -v gocyclo 2> /dev/null)
ifndef GOCYCLO_CMD
go get -u github.com/fzipp/gocyclo
endif
ineffassign: install-ineffassign
ineffassign ${GOFILES_NOVENDOR}
gocyclo: install-gocyclo
gocyclo -over 18 ${GOFILES_NOVENDOR}
install-go-junit-report:
GOLINT_CMD=$(shell command -v go-junit-report 2> /dev/null)
ifndef GOLINT_CMD
go get -u github.com/jstemmer/go-junit-report
endif
go-junit-report: install-go-junit-report
$(shell mkdir -p test-results)
cat test.txt | go-junit-report > test-results/report.xml