-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
83 lines (61 loc) · 2.8 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
GOBIN = $(GOPATH)/bin
help:
@echo "Please use 'make <target>' where <target> is one of the following:"
@echo " dev-dependencies to install all required Go dev dependencies"
@echo " gomod to run tidy you go.mod file and load vendor files."
@echo " update-mocks to update mocks."
@echo " gofumpt to apply gofumpt."
@echo " gci to apply gci."
@echo " lint to perform linting."
@echo " test run all unit tests."
@echo " coverage-report open coverage report generated by make test."
@echo " ci-all to run all CI steps in one command."
@echo " ci-initialize initialize the CI Docker container."
@echo " ci-lint run the linting in the CI Docker container."
@echo " ci-test run the tests in the CI Docker container."
@echo " ci-cleanup to kill & remove all ci containers."
dev-dependencies: | $(GOBIN)/mockgen $(GOBIN)/gofumpt $(GOBIN)/gci $(GOBIN)/golangci-lint
gomod:
@go mod tidy
@go mod vendor
$(GOBIN)/mockgen:
@go install github.com/golang/mock/mockgen@v1.6.0
@$(MAKE) gomod
update-mocks: | $(GOBIN)/mockgen
@find ./mocks ! -name 'definition.go' -type f -exec rm {} +
GO111MODULE=on go generate -mod=vendor -tags=mocks ./...
@$(MAKE) gofumpt
@$(MAKE) gci
$(GOBIN)/gofumpt:
@go install mvdan.cc/gofumpt@v0.3.1
@$(MAKE) gomod
gofumpt: | $(GOBIN)/gofumpt
@gofumpt -w $(shell ls -d $(PWD) | grep -v vendor)
$(GOBIN)/gci:
@go install github.com/daixiang0/gci@v0.3.3
@$(MAKE) gomod
gci: | $(GOBIN)/gci
@gci write --Section Standard --Section Default --Section "Prefix(github.com/taxibeat/authentication-service)" $(shell ls -d $(PWD) | grep -v vendor)
$(GOBIN)/golangci-lint:
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.45.0
lint: | $(GOBIN)/golangci-lint
golangci-lint run -v
test:
@mkdir -p reports
@go test -coverprofile=reports/codecoverage_all.cov ./... -mod=vendor -cover -race -p=4
@go tool cover -func=reports/codecoverage_all.cov > reports/functioncoverage.out
@go tool cover -html=reports/codecoverage_all.cov -o reports/coverage.html
@echo "View report at $(PWD)/reports/coverage.html"
@tail -n 1 reports/functioncoverage.out
coverage-report:
@open reports/coverage.html
ci-all: ci-initialize ci-lint ci-test ci-cleanup
ci-initialize:
docker-compose -f ./infra/build/docker-compose.ci.yaml build
ci-lint:
docker-compose -f ./infra/build/docker-compose.ci.yaml run ctxlog-ci make lint
ci-test:
docker-compose -f ./infra/build/docker-compose.ci.yaml run ctxlog-ci make test
ci-cleanup:
docker-compose -f ./infra/build/docker-compose.ci.yaml down
.PHONY: help dev-dependencies gomod update-mocks gofumpt gci lint test coverage-report ci-initialize ci-lint ci-test ci-cleanup