forked from vulsio/go-cpe-dictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNUmakefile
121 lines (100 loc) · 3.73 KB
/
GNUmakefile
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
.PHONY: \
all \
build \
install \
lint \
golangci \
vet \
fmt \
fmtcheck \
pretest \
test \
integration \
cov \
clean \
build-integration \
clean-integration \
fetch-rdb \
fetch-redis \
diff-server-rdb \
diff-server-redis \
diff-server-rdb-redis
SRCS = $(shell git ls-files '*.go')
PKGS = $(shell go list ./...)
VERSION := $(shell git describe --tags --abbrev=0)
REVISION := $(shell git rev-parse --short HEAD)
LDFLAGS := -X 'github.com/vulsio/go-cpe-dictionary/config.Version=$(VERSION)' \
-X 'github.com/vulsio/go-cpe-dictionary/config.Revision=$(REVISION)'
GO := CGO_ENABLED=0 go
all: build test
build: main.go
$(GO) build -ldflags "$(LDFLAGS)" -o go-cpe-dictionary $<
install: main.go
$(GO) install -ldflags "$(LDFLAGS)"
lint:
go install github.com/mgechev/revive@latest
revive -config ./.revive.toml -formatter plain $(PKGS)
golangci:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run
vet:
echo $(PKGS) | xargs env $(GO) vet || exit;
fmt:
gofmt -w $(SRCS)
fmtcheck:
$(foreach file,$(SRCS),gofmt -d $(file);)
pretest: lint vet fmtcheck
test: pretest
$(GO) test -cover -v ./... || exit;
cov:
@ go get -v github.com/axw/gocov/gocov
@ go get golang.org/x/tools/cmd/cover
gocov test | gocov report
clean:
$(foreach pkg,$(PKGS),go clean $(pkg) || exit;)
PWD := $(shell pwd)
BRANCH := $(shell git symbolic-ref --short HEAD)
build-integration:
@ git stash save
$(GO) build -ldflags "$(LDFLAGS)" -o integration/go-cpe.new
git checkout $(shell git describe --tags --abbrev=0)
@git reset --hard
$(GO) build -ldflags "$(LDFLAGS)" -o integration/go-cpe.old
git checkout $(BRANCH)
-@ git stash apply stash@{0} && git stash drop stash@{0}
clean-integration:
-pkill go-cpe.old
-pkill go-cpe.new
-rm integration/go-cpe.old integration/go-cpe.new integration/go-cpe.old.sqlite3 integration/go-cpe.new.sqlite3
-rm -rf integration/diff
-docker kill redis-old redis-new
-docker rm redis-old redis-new
fetch-rdb:
integration/go-cpe.old fetch nvd --dbpath=$(PWD)/integration/go-cpe.old.sqlite3
integration/go-cpe.old fetch jvn --dbpath=$(PWD)/integration/go-cpe.old.sqlite3
integration/go-cpe.new fetch nvd --dbpath=$(PWD)/integration/go-cpe.new.sqlite3
integration/go-cpe.new fetch jvn --dbpath=$(PWD)/integration/go-cpe.new.sqlite3
fetch-redis:
docker run --name redis-old -d -p 127.0.0.1:6379:6379 redis
docker run --name redis-new -d -p 127.0.0.1:6380:6379 redis
integration/go-cpe.old fetch nvd --dbtype redis --dbpath "redis://127.0.0.1:6379/0"
integration/go-cpe.old fetch jvn --dbtype redis --dbpath "redis://127.0.0.1:6379/0"
integration/go-cpe.new fetch nvd --dbtype redis --dbpath "redis://127.0.0.1:6380/0"
integration/go-cpe.new fetch jvn --dbtype redis --dbpath "redis://127.0.0.1:6380/0"
diff-server-rdb:
integration/go-cpe.old server --dbpath=$(PWD)/integration/go-cpe.old.sqlite3 --port 1325 > /dev/null 2>&1 &
integration/go-cpe.new server --dbpath=$(PWD)/integration/go-cpe.new.sqlite3 --port 1326 > /dev/null 2>&1 &
@ python integration/diff_server_mode.py cpes --sample_rate 0.01
pkill go-cpe.old
pkill go-cpe.new
diff-server-redis:
integration/go-cpe.old server --dbtype redis --dbpath "redis://127.0.0.1:6379/0" --port 1325 > /dev/null 2>&1 &
integration/go-cpe.new server --dbtype redis --dbpath "redis://127.0.0.1:6380/0" --port 1326 > /dev/null 2>&1 &
@ python integration/diff_server_mode.py cpes --sample_rate 0.01
pkill go-cpe.old
pkill go-cpe.new
diff-server-rdb-redis:
integration/go-cpe.new server --dbpath=$(PWD)/integration/go-cpe.new.sqlite3 --port 1325 > /dev/null 2>&1 &
integration/go-cpe.new server --dbtype redis --dbpath "redis://127.0.0.1:6380/0" --port 1326 > /dev/null 2>&1 &
@ python integration/diff_server_mode.py cpes --sample_rate 0.01
pkill go-cpe.new