-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
62 lines (47 loc) · 2.25 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
# This repo's root import path.
PKG := gitlab.com/screwyprof/cqrs
## DO NOT EDIT BELLOW THIS LINE
SHELL := bash
GO_FILES = $(shell find . -name "*.go" | uniq)
GO_PACKAGES = $(shell go list ./... | tr '\n', ',')
LOCAL_PACKAGES="github.com/screwyprof/"
IGNORE_COVERAGE_FOR= -e .*test
OK_COLOR=\033[32;01m
NO_COLOR=\033[0m
MAKE_COLOR=\033[33;01m%-20s\033[0m
all: tools lint test ## install tools, lint and test
deps: ## install dependencies
@echo -e "$(OK_COLOR)--> Downloading go.mod dependencies$(NO_COLOR)"
@go mod download
tools: ## install dev tools, linters, code generators, etc..
@echo -e "$(OK_COLOR)--> Installing tools from tools/tools.go$(NO_COLOR)"
@export GOBIN=$$PWD/tools/bin; export PATH=$$GOBIN:$$PATH; cat tools/tools.go | grep _ | awk -F'"' '{print $$2}' | xargs -tI % go install %
lint: ## run linters for the current changes
@echo -e "$(OK_COLOR)--> Running linters$(NO_COLOR)"
@tools/bin/golangci-lint run
lint-all: ## run linters
@echo -e "$(OK_COLOR)==> Linting$(NO_COLOR)"
golangci-lint run ./... --new-from-rev=""
test: ## run tests
@echo -e "$(OK_COLOR)--> Running unit tests$(NO_COLOR)"
go test -v --race --count=1 -covermode atomic -coverprofile=coverage.tmp ./...
@set -euo pipefail && cat coverage.tmp | grep -v $(IGNORE_COVERAGE_FOR) > coverage.out && rm coverage.tmp
coverage: test ## show test coverage report
@echo -e "$(OK_COLOR)--> Showing test coverage$(NO_COLOR)"
@go tool cover -func=coverage.out
fmt: ## format go files
@echo -e "$(OK_COLOR)--> Formatting go files$(NO_COLOR)"
@go mod tidy
@go fmt ./...
@tools/bin/gofumpt -l -w .
@tools/bin/gci write $(GO_FILES) -s standard -s default -s "prefix($(LOCAL_PACKAGES))"
clean: ## remove tools
@echo -e "$(OK_COLOR)--> Clean up$(NO_COLOR)"
rm -rf $(PWD)/tools/bin
rm -rf coverage.txt *.out *.tmp
help: ## show this help screen
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " $(MAKE_COLOR) %s\n", $$1, $$2 } /^##@/ { printf "\n$(MAKE_COLOR)\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: all deps tools lint lint-all test coverage fmt clean help