-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
GNUmakefile
141 lines (116 loc) · 4.03 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
.PHONY: \
all \
build \
install \
lint \
golangci \
vet \
fmt \
fmtcheck \
pretest \
test \
cov \
clean \
build-integration \
clean-integration \
fetch-rdb \
fetch-redis \
diff-cveid \
diff-package \
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)
BUILDTIME := $(shell date "+%Y%m%d_%H%M%S")
LDFLAGS := -X 'github.com/vulsio/go-cve-dictionary/config.Version=$(VERSION)' \
-X 'github.com/vulsio/go-cve-dictionary/config.Revision=$(REVISION)'
GO := CGO_ENABLED=0 go
all: build test
build: main.go
$(GO) build -ldflags "$(LDFLAGS)" -o go-cve-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:
echo $(PKGS) | xargs go clean || exit;
PWD := $(shell pwd)
BRANCH := $(shell git symbolic-ref --short HEAD)
build-integration:
@ git stash save
$(GO) build -ldflags "$(LDFLAGS)" -o integration/go-cve.new
git checkout $(shell git describe --tags --abbrev=0)
@git reset --hard
$(GO) build -ldflags "$(LDFLAGS)" -o integration/go-cve.old
git checkout $(BRANCH)
-@ git stash apply stash@{0} && git stash drop stash@{0}
clean-integration:
-pkill go-cve.old
-pkill go-cve.new
-rm integration/go-cve.old integration/go-cve.new integration/cve.old.sqlite3 integration/cve.new.sqlite3
-rm -rf integration/diff
-docker kill redis-old redis-new
-docker rm redis-old redis-new
fetch-rdb:
integration/go-cve.old fetch nvd --dbpath=$(PWD)/integration/cve.old.sqlite3
integration/go-cve.old fetch jvn --dbpath=$(PWD)/integration/cve.old.sqlite3
integration/go-cve.new fetch nvd --dbpath=$(PWD)/integration/cve.new.sqlite3
integration/go-cve.new fetch jvn --dbpath=$(PWD)/integration/cve.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-cve.old fetch nvd --dbtype redis --dbpath "redis://127.0.0.1:6379/0"
integration/go-cve.old fetch jvn --dbtype redis --dbpath "redis://127.0.0.1:6379/0"
integration/go-cve.new fetch nvd --dbtype redis --dbpath "redis://127.0.0.1:6380/0"
integration/go-cve.new fetch jvn --dbtype redis --dbpath "redis://127.0.0.1:6380/0"
diff-cveid:
@ python integration/diff_server_mode.py cves --sample_rate 0.01
diff-cpes:
@ python integration/diff_server_mode.py cpes --sample_rate 0.01
@ python integration/diff_server_mode.py cpe_ids --sample_rate 0.01
diff-server-rdb:
- pkill -KILL go-cve.old
- pkill -KILL go-cve.new
integration/go-cve.old server --dbpath=$(PWD)/integration/cve.old.sqlite3 --port 1325 > /dev/null 2>&1 &
integration/go-cve.new server --dbpath=$(PWD)/integration/cve.new.sqlite3 --port 1326 > /dev/null 2>&1 &
make diff-cveid
make diff-cpes
pkill go-cve.old
pkill go-cve.new
diff-server-redis:
- pkill -KILL go-cve.old
- pkill -KILL go-cve.new
integration/go-cve.old server --dbtype redis --dbpath "redis://127.0.0.1:6379/0" --port 1325 > /dev/null 2>&1 &
integration/go-cve.new server --dbtype redis --dbpath "redis://127.0.0.1:6380/0" --port 1326 > /dev/null 2>&1 &
make diff-cveid
make diff-cpes
pkill go-cve.old
pkill go-cve.new
diff-server-rdb-redis:
- pkill -KILL go-cve.old
- pkill -KILL go-cve.new
integration/go-cve.new server --dbpath=$(PWD)/integration/cve.new.sqlite3 --port 1325 > /dev/null 2>&1 &
integration/go-cve.new server --dbtype redis --dbpath "redis://127.0.0.1:6380/0" --port 1326 > /dev/null 2>&1 &
make diff-cveid
make diff-cpes
pkill go-cve.new