-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
55 lines (49 loc) · 2.01 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
RED=\033[31m
GREEN=\033[32m
RESET=\033[0m
COLORIZE_PASS = sed "s/^\([- ]*\)\(PASS\)/\1$$(printf "$(GREEN)")\2$$(printf "$(RESET)")/g"
COLORIZE_FAIL = sed "s/^\([- ]*\)\(FAIL\)/\1$$(printf "$(RED)")\2$$(printf "$(RESET)")/g"
VERSION := $(shell git describe --tags --abbrev=0)
REVISION := $(shell git rev-parse --short HEAD)
LDFLAGS := -s -w \
-X 'github.com/go-to-k/lamver/internal/version.Version=$(VERSION)' \
-X 'github.com/go-to-k/lamver/internal/version.Revision=$(REVISION)'
GO_FILES := $(shell find . -type f -name '*.go' -print)
DIFF_FILE := "$$(git diff --name-only --diff-filter=ACMRT | grep .go$ | xargs -I{} dirname {} | sort | uniq | xargs -I{} echo ./{})"
TEST_DIFF_RESULT := "$$(go test -race -cover -v $$(echo $(DIFF_FILE)) -coverpkg=./...)"
TEST_FULL_RESULT := "$$(go test -race -cover -v ./... -coverpkg=./...)"
TEST_COV_RESULT := "$$(go test -race -cover -v ./... -coverpkg=./... -coverprofile=cover.out.tmp)"
FAIL_CHECK := "^[^\s\t]*FAIL[^\s\t]*$$"
test_diff:
@! echo $(TEST_DIFF_RESULT) | $(COLORIZE_PASS) | $(COLORIZE_FAIL) | tee /dev/stderr | grep $(FAIL_CHECK) > /dev/null
test:
@! echo $(TEST_FULL_RESULT) | $(COLORIZE_PASS) | $(COLORIZE_FAIL) | tee /dev/stderr | grep $(FAIL_CHECK) > /dev/null
test_view:
@! echo $(TEST_COV_RESULT) | $(COLORIZE_PASS) | $(COLORIZE_FAIL) | tee /dev/stderr | grep $(FAIL_CHECK) > /dev/null
cat cover.out.tmp | grep -v "**_mock.go" > cover.out
rm cover.out.tmp
go tool cover -func=cover.out
go tool cover -html=cover.out -o cover.html
lint:
golangci-lint run
lint_diff:
golangci-lint run $$(echo $(DIFF_FILE))
mockgen:
go generate ./...
deadcode:
deadcode ./...
shadow:
find . -type f -name '*.go' | sed -e "s/\/[^\.\/]*\.go//g" | uniq | xargs shadow
cognit:
gocognit -top 10 ./ | grep -v "_test.go"
run:
go mod tidy
go run -ldflags "$(LDFLAGS)" cmd/lamver/main.go $${OPT}
build: $(GO_FILES)
go mod tidy
go build -ldflags "$(LDFLAGS)" -o lamver cmd/lamver/main.go
install:
go install -ldflags "$(LDFLAGS)" github.com/go-to-k/lamver/cmd/lamver
clean:
go clean
rm -f lamver