-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
79 lines (61 loc) · 2.49 KB
/
Makefile
File metadata and controls
79 lines (61 loc) · 2.49 KB
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
ENV_LOCAL_TEST=\
TESTING_DATABASE_URL=postgres://matrix:s3cr3t@localhost:5431/matrix?sslmode=disable \
POSTGRES_PASSWORD=s3cr3t \
POSTGRES_DB=matrix \
POSTGRES_HOST=localhost \
POSTGRES_USER=matrix \
TESTING_CACHE_URI=redis://matrix:s3cr3t@localhost:6378 \
TESTING_QUEUE_URI=nats://matrix:s3cr3t@localhost:4221
SERVICE ?= $(shell basename `go list`)
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || cat $(PWD)/.version 2> /dev/null || echo v0)
PACKAGE ?= $(shell go list)
PACKAGES ?= $(shell go list ./...)
FILES ?= $(shell find . -type f -name '*.go' -not -path "./vendor/*")
default: generate-grpc format build
help: ## show this help
@echo 'usage: make [target] ...'
@echo ''
@echo 'targets:'
@egrep '^(.+)\:\ .*##\ (.+)' ${MAKEFILE_LIST} | sed 's/:.*##/#/' | column -t -c 2 -s '#'
format:
find . -name '*.go' -not -path './.git/*' -exec sed -i '/^import (/,/^)/{/^$$/d}' {} +
find . -name '*.go' -not -path './.git/*' -exec goimports -w {} +
golangci-lint run --fix
clean: ## go clean
go clean
fmt: ## format the go source files
go fmt ./...
vet: ## run go vet on the source files
go vet ./...
doc: ## generate godocs and start a local documentation webserver on port 8085
godoc -http=:8085 -index
.PHONY: build generate-grpc
generate-grpc:
@echo "Generating gRPC code..."
@cd apis && ./generate.sh
@echo "gRPC code generation completed"
# this command will start docker components that we set in docker-compose.yml
docker-setup: ## sets up docker container images
docker compose up -d --remove-orphans --force-recreate
pg_wait:
@count=0; \
until nc -z localhost 5431; do \
if [ $$count -gt 30 ]; then echo "can't wait forever for pg"; exit 1; fi; \
sleep 1; echo "waiting for postgresql" $$count; count=$$(($$count+1)); done; \
sleep 5;
# shutting down docker components
docker-stop: ## stops all docker containers
docker compose down
# this command will run all tests in the repo
# INTEGRATION_TEST_SUITE_PATH is used to run specific tests in Golang,
# if it's not specified it will run all tests
tests: ## runs all system tests
$(ENV_LOCAL_TEST) \
go test ./... -v -run=$(INTEGRATION_TEST_SUITE_PATH) -coverprofile=coverage.out;\
RETURNCODE=$$?;\
if [ "$$RETURNCODE" -ne 0 ]; then\
echo "unit tests failed with error code: $$RETURNCODE" >&2;\
exit 1;\
fi;\
go tool cover -html=coverage.out -o coverage.html
build: clean fmt vet docker-setup pg_wait tests docker-stop ## run all preliminary steps and tests the setup