-
Notifications
You must be signed in to change notification settings - Fork 129
/
Makefile
75 lines (60 loc) · 2.35 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
71
72
73
74
75
.PHONY: deps test lint lint-check-deps ci-check run-migrations
deps:
@if [ "$(go mod help | echo 'no-mod')" = "no-mod" ] || [ "${GO111MODULE}" = "off" ]; then \
echo "[dep] fetching package dependencies";\
go get -u github.com/golang/dep/cmd/dep;\
dep ensure;\
else \
go get ./...; \
fi
test:
@echo "[go test] running tests and collecting coverage metrics"
@go test -v -tags all_tests -race -coverprofile=coverage.txt -covermode=atomic ./...
lint: lint-check-deps
@echo "[golangci-lint] linting sources"
@golangci-lint run \
-E misspell \
-E golint \
-E gofmt \
-E unconvert \
--exclude-use-default=false \
-e SA1019 \
--timeout 5m \
./...
lint-check-deps:
@if [ -z `which golangci-lint` ]; then \
echo "[go get] installing golangci-lint";\
GO111MODULE=on go get -u github.com/golangci/golangci-lint/cmd/golangci-lint;\
fi
ci-check: deps lint run-cdb-migrations test
run-db-migrations: run-cdb-migrations
# CH06: CockroachDB migrations
.PHONY: run-cdb-migrations migrate-check-deps check-cdb-env
run-cdb-migrations: migrate-check-deps check-cdb-env
migrate -source file://Chapter06/linkgraph/store/cdb/migrations -database '$(subst postgresql,cockroach,${CDB_DSN})' up
migrate-check-deps:
@if [ -z `which migrate` ]; then \
echo "[go get] installing golang-migrate cmd with cockroachdb support";\
if [ "${GO111MODULE}" = "off" ]; then \
echo "[go get] installing github.com/golang-migrate/migrate/cmd/migrate"; \
go get -tags 'cockroachdb postgres' -u github.com/golang-migrate/migrate/cmd/migrate;\
go install -tags 'cockroachdb postgres' github.com/golang-migrate/migrate/cmd/migrate;\
else \
echo "[go get] installing github.com/golang-migrate/migrate/v4/cmd/migrate"; \
go get -tags 'cockroachdb postgres' -u github.com/golang-migrate/migrate/v4/cmd/migrate;\
go install -tags 'cockroachdb postgres' github.com/golang-migrate/migrate/v4/cmd/migrate;\
fi \
fi
define dsn_missing_error
CDB_DSN envvar is undefined. To run the migrations this envvar
must point to a cockroach db instance. For example, if you are
running a local cockroachdb (with --insecure) and have created
a database called 'linkgraph' you can define the envvar by
running:
export CDB_DSN='postgresql://root@localhost:26257/linkgraph?sslmode=disable'
endef
export dsn_missing_error
check-cdb-env:
ifndef CDB_DSN
$(error ${dsn_missing_error})
endif