-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
59 lines (46 loc) · 2.17 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
CURRENTPACKAGE := github.com/Syncano/pkg-go
PATH := $(PATH):$(GOPATH)/bin
GOFILES=$(shell find . -mindepth 2 -type f -name '*.go' ! -path "./.*" ! -path "./dev/*" ! -path "*/proto/*")
GOTESTPACKAGES = $(shell find . -mindepth 2 -type f -name '*.go' ! -path "./.*" ! -path "./internal/*" ! -path "./dev/*" ! -path "*/mocks/*" ! -path "*/proto/*" | xargs -n1 dirname | sort | uniq)
.PHONY: help clean lint fmt test stest cov goconvey lint-in-docker test-in-docker generate
.DEFAULT_GOAL := help
$(VERBOSE).SILENT:
help:
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
require-%:
if ! hash ${*} 2>/dev/null; then \
echo "! ${*} not installed"; \
exit 1; \
fi
clean: ## Cleanup repository
go clean ./...
rm -f build/$(EXECNAME)
find deploy -name "*.unenc" -delete
git clean -f
lint: ## Run lint checks
echo "=== lint ==="
if ! hash golangci-lint 2>/dev/null; then \
echo "Installing golangci-lint"; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $$(go env GOPATH)/bin v1.27.0; \
fi
golangci-lint run $(ARGS)
fmt: ## Format code through goimports
gofmt -s -w $(GOFILES)
go run golang.org/x/tools/cmd/goimports -local $(CURRENTPACKAGE) -w $(GOFILES)
test: ## Run unit with race check and create coverage profile
echo "=== unit test ==="
echo "mode: atomic" > coverage-all.out
$(foreach pkg,$(GOTESTPACKAGES),\
go test -timeout 5s -short -race -coverprofile=coverage.out -covermode=atomic $(ARGS) $(pkg) || exit;\
tail -n +2 coverage.out >> coverage-all.out 2>/dev/null;)
cov: ## Show per function coverage generated by test
echo "=== coverage ==="
go tool cover -func=coverage-all.out
goconvey: ## Run goconvey test server
go run github.com/smartystreets/goconvey -excludedDirs "dev,internal,mocks,proto,assets,deploy,build" -timeout 5s -depth 2
lint-in-docker: require-docker-compose ## Run lint in docker environment
docker-compose run --no-deps --rm server make lint
test-in-docker: require-docker-compose ## Run full test suite in docker environment
docker-compose run --rm server make build test
generate: ## Run go generate
go generate ./...