Files
go-caatsm/Makefile
T

106 lines
3.3 KiB
Makefile
Raw Normal View History

# Build variables
BUILD_DIR ?= bin
BINARY := $(BUILD_DIR)/receiver
CMD := ./cmd/main
GO_ENV ?= dev
2024-07-19 20:02:18 +08:00
# Default target
.PHONY: all
all: build ## Build the application
2024-07-19 20:02:18 +08:00
.PHONY: build
build: ## Build the receiver binary
@mkdir -p $(BUILD_DIR)
2024-07-19 20:02:18 +08:00
@echo "Building receiver..."
@go build -o $(BINARY) $(CMD)
2024-07-19 20:02:18 +08:00
.PHONY: run
run: run-dev ## Alias for run-dev
2024-07-19 20:02:18 +08:00
.PHONY: run-dev
run-dev: build ## Run the receiver in development mode (uses core NATS mode by default)
@echo "Running receiver in development mode (NATS mode: core by default)..."
@GO_ENV=dev $(BINARY) listen
2024-07-19 20:02:18 +08:00
.PHONY: run-prod
run-prod: build ## Run the receiver in production mode (requires config.prod.toml and JetStream mode)
2024-07-19 20:02:18 +08:00
@echo "Running receiver in production mode..."
@echo "Note: Production mode requires:"
@echo " - configs/config.prod.toml file (or CAATSM_* environment variables)"
@echo " - NATS JetStream enabled (nats.mode = jetstream)"
@echo " - Stream and Consumer must exist (not auto-created in prod)"
@echo " - PostgreSQL connection configured"
@GO_ENV=prod $(BINARY) listen
2024-07-19 20:02:18 +08:00
.PHONY: run-test
run-test: build ## Run the receiver in test mode
2024-07-19 20:02:18 +08:00
@echo "Running receiver in test mode..."
@GO_ENV=test $(BINARY) listen
.PHONY: run-local
run-local: ## Run receiver directly via go run (uses core NATS mode by default in dev)
@echo "Running receiver via go run (GO_ENV=$(GO_ENV), NATS mode: core by default in dev)..."
@GO_ENV=$(GO_ENV) go run $(CMD) listen
2024-07-19 20:02:18 +08:00
.PHONY: test
test: ## Run unit tests (Ginkgo, verbose)
@command -v ginkgo >/dev/null || (echo "Please install ginkgo (go install github.com/onsi/ginkgo/v2/ginkgo@latest)"; exit 1)
@echo "Running Ginkgo unit test suites (verbose)..."
@ginkgo -r -v ./cmd ./internal
2024-07-19 20:02:18 +08:00
.PHONY: test-int
test-int: ## Run integration tests (requires Docker)
@echo "Running integration tests..."
@GO_ENV=$(GO_ENV) go test -tags=integration ./test/integration/...
.PHONY: test-ginkgo
test-ginkgo: test ## Alias for test (Ginkgo)
.PHONY: test-all
test-all: ## Run unit tests (Ginkgo) and integration tests
@$(MAKE) test
@$(MAKE) test-int
.PHONY: coverage
coverage: ## Run coverage and generate report
@mkdir -p coverage
@echo "Generating coverage report..."
@go test ./... -coverprofile=coverage/coverage.out
@go tool cover -html=coverage/coverage.out -o coverage/coverage.html
2024-07-19 20:02:18 +08:00
.PHONY: fmt
fmt: ## Format Go code
2024-07-19 20:02:18 +08:00
@echo "Formatting code..."
@go fmt ./...
.PHONY: wire
wire: ## Generate wire dependency injection code
@command -v wire >/dev/null || (echo "Please install wire (go install github.com/google/wire/cmd/wire@latest)"; exit 1)
@echo "Generating wire code..."
@wire ./pkg/di
.PHONY: generate
generate: wire ## Generate all code (wire, etc.)
@echo "Code generation complete"
2024-07-19 20:02:18 +08:00
.PHONY: deps
deps: ## Sync go.mod / go.sum
@echo "Tidying go modules..."
2024-07-19 20:02:18 +08:00
@go mod tidy
.PHONY: lint
lint: ## Run golangci-lint
@command -v golangci-lint >/dev/null || (echo "Please install golangci-lint (https://golangci-lint.run/)"; exit 1)
2024-07-19 20:02:18 +08:00
@echo "Linting code..."
@golangci-lint run ./...
.PHONY: clean
clean: ## Clean build artifacts and coverage files
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR) coverage
2024-07-19 20:02:18 +08:00
.PHONY: help
help: ## Show this help
@printf "Makefile targets:\n"
@grep -E '^[a-zA-Z0-9_-]+:.*##' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*##"} {printf " %-15s %s\n", $$1, $$2}'