-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMakefile
More file actions
155 lines (121 loc) · 5.03 KB
/
Copy pathMakefile
File metadata and controls
155 lines (121 loc) · 5.03 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Variables
APP_NAME=authula
BINARY_PATH=./tmp/$(APP_NAME)
MIGRATE_CONFIG?=./config.toml
MIGRATE_ARGS?=
MIGRATE_CMD=CGO_ENABLED=0 go run ./cmd/migrate
OPENAPI_EXPORT_BINARY=./tmp/openapi-export
BIN_DIR=$(CURDIR)/bin
GOLANGCI_LINT_VERSION?=v2.13.2
AIR_VERSION?=latest
.PHONY: help build build-exe run dev test clean install setup tools hooks hooks-uninstall
.PHONY: test-coverage
.PHONY: lint format vet deps-update all check quick-check ci
.PHONY: migrate-core-up migrate-core-down migrate-plugins-up migrate-plugins-down migrate-status
.PHONY: openapi-export
# Help command
help: # Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# Build commands`
build: # Build the package (library)
@echo "Building $(APP_NAME) package..."
@CGO_ENABLED=0 go build ./...
@echo "Build complete!"
build-exe: # Build the binary executable
@echo "Building $(APP_NAME) binary..."
@mkdir -p ./tmp
@rm -rf ./tmp/$(APP_NAME)
@CGO_ENABLED=0 go build -o $(BINARY_PATH) ./cmd/main.go
@echo "Binary built: $(BINARY_PATH)"
run: # Run the application
@rm -f ./tmp/$(APP_NAME)
@CGO_ENABLED=0 go run ./cmd/main.go
dev: # Run the application with live reloading using air
@rm -f ./tmp/$(APP_NAME)
@CGO_ENABLED=0 ./bin/air --build.cmd "go build -o ./tmp/$(APP_NAME) ./cmd/main.go" --build.entrypoint "./tmp/$(APP_NAME)"
openapi-export:
@echo "Exporting OpenAPI spec..."
@CGO_ENABLED=0 go run ./cmd/openapi/ $(ARGS)
@echo "Done!"
# Test commands
# CGO_ENABLED=1 is required by the race detector, not by any dependency of the build.
test: # Run all tests
@echo "Running tests..."
@CGO_ENABLED=1 go test -race -v ./...
test-coverage: # Run tests with coverage report
@echo "Running tests with coverage..."
@CGO_ENABLED=1 go test -race -v -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
@go tool cover -func=coverage.out | grep total | awk '{print "Total coverage: " $$3}'
# Dependency management
install: # Install dependencies
@echo "Installing dependencies..."
@go mod download
@go mod tidy
deps-update: # Update dependencies
@echo "Updating dependencies..."
@go get -u ./...
@go mod tidy
# Library mode development
library-test: test # Run library mode tests
# Development setup
setup: install tools hooks # Setup development environment (deps, tools in ./bin, git hooks)
@echo "Development environment setup complete!"
tools: # Install development tools (golangci-lint, air) into ./bin
@echo "Installing development tools into $(BIN_DIR)..."
@mkdir -p $(BIN_DIR)
@curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(BIN_DIR) $(GOLANGCI_LINT_VERSION)
@GOBIN=$(BIN_DIR) go install github.com/air-verse/air@$(AIR_VERSION)
@echo "Tools installed: $(BIN_DIR)/golangci-lint, $(BIN_DIR)/air"
# Git hooks
hooks: # Install git hooks (pre-commit runs format, vet, lint, build and test)
@echo "Installing git hooks..."
@chmod +x .githooks/* scripts/pre-commit-checks.sh
@git config core.hooksPath .githooks
@echo "Git hooks installed (core.hooksPath=.githooks)"
hooks-uninstall: # Remove the git hooks configuration
@git config --unset core.hooksPath || true
@echo "Git hooks uninstalled"
# Clean commands
clean: # Clean build artifacts
@echo "Cleaning..."
@rm -rf bin/
@rm -f coverage.out coverage.html
@go clean
# Code quality
lint: # Run linter
@echo "Running linter..."
@./bin/golangci-lint run
format: # Format code
@echo "Formatting code..."
@go fmt ./...
vet: # Run go vet
@echo "Running go vet..."
@go vet ./...
# All-in-one commands
all: clean install build check # Clean, install deps, build, and run all checks
check: build test format lint vet # Run all checks
quick-check: format vet test # Run quick checks (format, vet, fast tests)
ci: clean install check # CI pipeline (clean, install, check)
# Integration testing
integration-test: docker-down docker-up docker-test # Run integration tests with Docker
# Migration commands
migrate-help: # Show migration CLI help
@$(MIGRATE_CMD) --help
migrate-core-up: # Run core migrations (up)
@$(MIGRATE_CMD) core up --config $(MIGRATE_CONFIG) $(MIGRATE_ARGS)
migrate-core-down: # Roll back core migrations
@$(MIGRATE_CMD) core down --config $(MIGRATE_CONFIG) $(MIGRATE_ARGS)
migrate-plugins-up: # Run plugin migrations (up) - use MIGRATE_ARGS for filtering (e.g., --only email-password)
@$(MIGRATE_CMD) plugins up --config $(MIGRATE_CONFIG) $(MIGRATE_ARGS)
migrate-plugins-down: # Roll back plugin migrations - use MIGRATE_ARGS for filtering (e.g., --except email-password)
@$(MIGRATE_CMD) plugins down --config $(MIGRATE_CONFIG) $(MIGRATE_ARGS)
migrate-status: # Show migration status - use MIGRATE_ARGS to filter by plugin (e.g., --plugin jwt)
@$(MIGRATE_CMD) status --config $(MIGRATE_CONFIG) $(MIGRATE_ARGS)
# Run all migrations (core + plugins)
migrate-up: migrate-core-up migrate-plugins-up
# Roll back all migrations (core + plugins)
migrate-down: migrate-plugins-down migrate-core-down
# Default target
.DEFAULT_GOAL := help