-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathMakefile
More file actions
63 lines (44 loc) · 2.08 KB
/
Copy pathMakefile
File metadata and controls
63 lines (44 loc) · 2.08 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
.DEFAULT_GOAL := help
# Local database URL used by migrate-* targets. Override on the CLI:
# make migrate-up DATABASE_URL=postgres://user:pass@host:5432/db?sslmode=disable
DATABASE_URL ?= postgres://marketplace:marketplace@localhost:5432/marketplace?sslmode=disable
GOVULNCHECK_VERSION := v1.6.0
# Packages whose tests require Docker (testcontainers).
DOCKER_TEST_PKGS := github.com/sklinkert/go-ddd/internal/infrastructure/db/postgres \
github.com/sklinkert/go-ddd/internal/testhelpers
.PHONY: help build run test test-unit cover lint vulncheck fmt tidy vendor sqlc migrate-up migrate-down docker-up docker-down
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-14s\033[0m %s\n", $$1, $$2}'
build: ## Build the server binary
go build -o bin/marketplace ./cmd/marketplace
run: ## Run the server locally
go run ./cmd/marketplace
test: ## Run all tests with the race detector (needs Docker)
go test -race ./...
test-unit: ## Run only tests that don't need Docker
go test -race $(filter-out $(DOCKER_TEST_PKGS),$(shell go list ./...))
cover: ## Run all tests and print total coverage (needs Docker)
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | tail -1
lint: ## Run golangci-lint
golangci-lint run ./...
vulncheck: ## Scan application and test code for known vulnerabilities
go run golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION) -test ./...
fmt: ## Format code (gofmt + goimports)
golangci-lint fmt ./...
tidy: ## Tidy and re-vendor modules
go mod tidy
go mod vendor
vendor: ## Re-vendor modules
go mod vendor
sqlc: ## Regenerate sqlc code from sql/queries
sqlc generate
migrate-up: ## Apply all pending migrations
go run migrate.go -database-url "$(DATABASE_URL)" -command up
migrate-down: ## Roll back the last migration
go run migrate.go -database-url "$(DATABASE_URL)" -command down -steps 1
docker-up: ## Start Postgres + app via docker compose
docker compose up --build
docker-down: ## Stop and remove docker compose resources
docker compose down -v