-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
70 lines (56 loc) · 2.19 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
63
64
65
66
67
68
69
70
.PHONY: install lint init_db test unit_test integration_test mod generate
# Non-cgo DNS is more reliable and faster for non-esoteric uses of resolv.conf
export CGO_ENABLED = 0
RFLAG = -buildmode=pie
# Race detector is exclusive of non-cgo and PIE
# https://github.com/golang/go/issues/6508
ifneq ($(RACE),)
export CGO_ENABLED = 1
RFLAG = -race
export GORACE = halt_on_error=1
endif
ifeq ($(strip $(TEST_REDIS_HOST)),)
TEST_REDIS_HOST = 127.0.0.1
endif
ifeq ($(strip $(TEST_PG_URI)),)
TEST_PG_URI = pgx://postgres:[email protected]/atlas_test
endif
install:
for x in $(shell find cmd -mindepth 1 -type d); do go install $(RFLAG) \
-ldflags="-w" ./$${x}; done
for x in $(shell find tool -mindepth 1 -type d); do go install \
-ldflags="-w" ./$${x}; done
lint:
go install honnef.co/go/tools/cmd/staticcheck@latest
# staticcheck defaults are all,-ST1000,-ST1003,-ST1016,-ST1020,-ST1021,-ST1022
staticcheck -checks all ./...
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run -E bidichk,copyloopvar,durationcheck,err113,errname \
-E forcetypeassert,godot,gofumpt,gosec,intrange,nlreturn,perfsprint \
-E prealloc,protogetter,testifylint,unconvert,unparam,usestdlibvars \
--exclude-use-default=false
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck -test ./...
init_db:
echo FLUSHALL|nc -w 2 $(TEST_REDIS_HOST) 6379
go install -tags pgx github.com/golang-migrate/migrate/v4/cmd/migrate@latest
migrate -path /tmp -database $(TEST_PG_URI) drop -f
migrate -path config/db/atlas -database $(TEST_PG_URI) up
test: install lint unit_test integration_test
# -count=1 is the idiomatic way to disable test caching in package list mode
unit_test:
go test -count=1 -cover -cpu=1,4 -failfast -shuffle=on $(RFLAG) -tags unit \
./...
integration_test: init_db
go test -count=1 -cover -cpu=1,4 -failfast -shuffle=on $(RFLAG) -tags \
integration ./...
mod:
go get -t -u ./... || true
go mod tidy -v
go mod vendor
# Update atlas.swagger.json at the same time as github.com/thingspect/proto
if [ -f ../proto/openapi/atlas.swagger.json ]; then cp -f -v \
../proto/openapi/atlas.swagger.json web/; fi
generate:
go install go.uber.org/mock/mockgen@latest
go generate -x ./...