-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
107 lines (82 loc) · 2.99 KB
/
Makefile
File metadata and controls
107 lines (82 loc) · 2.99 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
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
BINARY := vaultkey
BUILD_DIR := bin
COVERAGE := coverage.out
GO := go
# Packages
UNIT_PKGS := ./internal/wallet/... ./internal/webhook/...
INT_PKGS := ./internal/nonce/... ./internal/queue/... ./internal/storage/...
DB_URL := postgres://vaultkey:${POSTGRES_PASSWORD:-changeme}@localhost:5432/vaultkey?sslmode=disable
.PHONY: all build build-api build-worker test test-unit test-integration lint coverage coverage-ci clean help
.PHONY: fmt docker-up docker-down docker-logs dev deps install-tools migrate-up migrate-down migrate-create
## all: build the binary (default target)
all: build
## build: compile the server binary
build:
@mkdir -p $(BUILD_DIR)
$(GO) build -o $(BUILD_DIR)/$(BINARY) ./cmd/server
## build-api: rebuild and restart the api container
build-api:
docker compose up -d --build api
## test: run unit tests then integration tests
test: test-unit test-integration
## test-unit: run unit tests (no Docker required, race detector on)
test-unit:
$(GO) test -race -count=1 -v $(UNIT_PKGS)
## test-integration: run integration tests (requires Docker, race detector on)
test-integration:
$(GO) test -race -count=1 -v -timeout 120s $(INT_PKGS)
## lint: run golangci-lint (install: https://golangci-lint.run/usage/install)
lint:
golangci-lint run ./...
## fmt: format code with gofmt
fmt:
$(GO) fmt ./...
gofmt -s -w .
## coverage: generate HTML coverage report and open it
coverage:
$(GO) test -coverprofile=$(COVERAGE) -covermode=atomic ./...
$(GO) tool cover -html=$(COVERAGE)
## coverage-ci: generate coverage report without opening browser (for CI)
coverage-ci:
$(GO) test -coverprofile=$(COVERAGE) -covermode=atomic ./...
$(GO) tool cover -func=$(COVERAGE)
## clean: remove build artifacts and coverage output
clean:
rm -rf $(BUILD_DIR) $(COVERAGE)
## docker-up: start Docker services
docker-up:
docker compose up -d
## docker-down: stop Docker services
docker-down:
docker compose down
## docker-logs: view Docker service logs
docker-logs:
docker compose logs -f
## migrate-create: create a new migration (usage: make migrate-create name=add_users)
migrate-create:
@if [ -z "$(name)" ]; then \
echo "Error: name is required. Usage: make migrate-create name=add_users"; \
exit 1; \
fi
@seq=$$(ls db/migrations/*.up.sql 2>/dev/null | wc -l | xargs printf '%06d'); \
touch db/migrations/$${seq}_$(name).up.sql db/migrations/$${seq}_$(name).down.sql; \
echo "created $${seq}_$(name).{up,down}.sql"
## run: start the VaultKey server
run:
$(GO) run ./cmd/server
## deps: download and tidy dependencies
deps:
$(GO) mod download
$(GO) mod tidy
## install-tools: install development tools
install-tools:
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
## help: print available targets
help:
@grep -E '^## ' $(MAKEFILE_LIST) | sed 's/## //' | column -t -s ':'
## swagger: generate OpenAPI spec from handler annotations
swagger:
swag init -g main.go -d ./cmd/server,./internal -o docs/
## swagger-fmt: format swagger comment blocks
swagger-fmt:
swag fmt