-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
155 lines (119 loc) · 4.59 KB
/
Copy pathMakefile
File metadata and controls
155 lines (119 loc) · 4.59 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
.PHONY: run stop restart build build-prod build-linux-amd64 build-darwin-arm64 build-all-platforms test coverage coverage-html clean clean-db migrate-up migrate-down migrate-status migrate-create assets dev sqlc templ deploy-binary commit-prepare commit-do code-quality security-audit commit-prepare-local commit-do-local code-quality-local security-audit-local install-hooks check-no-absolute-paths
# Build variables
BINARY_NAME=ocms
BUILD_DIR=bin
GO=go
GOFLAGS=-v
MAIN_DIR=./cmd/ocms
# Version info from git
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
# Linker flags for version injection
LDFLAGS_VERSION=-X main.appVersion=$(VERSION) -X main.appGitCommit=$(GIT_COMMIT) -X main.appBuildTime=$(BUILD_TIME)
# Database migrations (using goose CLI)
MIGRATIONS_DIR := internal/store/migrations
DB_PATH := ./data/ocms.db
# Build assets (SCSS to CSS)
assets:
./scripts/build-assets.sh
# Install repository-managed git hooks
install-hooks:
git config core.hooksPath .githooks
@echo "Configured git hooks path: .githooks"
# Scan tracked files for local absolute path leaks
check-no-absolute-paths:
./scripts/check-no-absolute-paths.sh --all
# Development server with asset build
dev: assets
go run $(MAIN_DIR)
# Development server (without asset build)
run:
go run $(MAIN_DIR)
# Stop development server
stop:
@lsof -ti:8080 -sTCP:LISTEN | xargs -r kill -9 2>/dev/null || true
@echo "Server stopped"
# Restart development server
restart: stop dev
# Build the application
build:
@echo "Building $(BINARY_NAME) $(VERSION)..."
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -ldflags="$(LDFLAGS_VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_DIR)
# Build with optimizations (smaller binary)
build-prod:
@echo "Building $(BINARY_NAME) $(VERSION) for production..."
@mkdir -p $(BUILD_DIR)
$(GO) build -ldflags="-s -w $(LDFLAGS_VERSION)" -trimpath -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_DIR)
# Build for Linux AMD64
build-linux-amd64:
@echo "Building $(BINARY_NAME) $(VERSION) for Linux AMD64..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -ldflags="-s -w $(LDFLAGS_VERSION)" -trimpath -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_DIR)
# Build for macOS ARM64 (Apple Silicon)
build-darwin-arm64:
@echo "Building $(BINARY_NAME) $(VERSION) for macOS ARM64..."
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GO) build -ldflags="-s -w $(LDFLAGS_VERSION)" -trimpath -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_DIR)
# Build for all platforms
build-all-platforms: build-linux-amd64 build-darwin-arm64
@echo "All platform builds complete!"
@ls -lh $(BUILD_DIR)/$(BINARY_NAME)-*
# Run tests
test:
go test -v ./...
# Test coverage summary
coverage:
go test -cover ./...
# Test coverage HTML report
coverage-html:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
@command -v open >/dev/null 2>&1 && open coverage.html || command -v xdg-open >/dev/null 2>&1 && xdg-open coverage.html || true
# Clean build artifacts
clean:
rm -rf bin/ coverage.out coverage.html
# Clean DB
clean-db:
rm -rf data/*.db
migrate-up:
goose -dir $(MIGRATIONS_DIR) sqlite3 $(DB_PATH) up
migrate-down:
goose -dir $(MIGRATIONS_DIR) sqlite3 $(DB_PATH) down
migrate-status:
goose -dir $(MIGRATIONS_DIR) sqlite3 $(DB_PATH) status
migrate-create:
@read -p "Migration name: " name; \
goose -dir $(MIGRATIONS_DIR) create $$name sql
# Generate SQLC code and fix unhandled errors
sqlc:
sqlc generate
@sed -i '' 's/defer rows\.Close()/defer func() { _ = rows.Close() }()/g' internal/store/*.sql.go
@echo "SQLC generated and warnings fixed"
# Generate templ Go code from .templ files
templ:
templ generate
@echo "Templ files generated"
# Deploy binary only to remote server
# Usage: make deploy-binary SERVER=server.example.com INSTANCES="site1 site2"
deploy-binary:
./scripts/deploy/deploy-binary.sh $(SERVER) $(INSTANCES) $(DEPLOY_OPTS)
# Prepare and execute commit workflow (Codex/Claude-compatible)
commit-prepare:
./scripts/codex-commands commit-prepare
commit-do:
./scripts/codex-commands commit-do
code-quality:
./scripts/codex-commands code-quality
security-audit:
./scripts/codex-commands security-audit
commit-prepare-local:
./scripts/codex-commands commit-prepare-local
commit-do-local:
./scripts/codex-commands commit-do-local
code-quality-local:
./scripts/codex-commands code-quality-local
security-audit-local:
./scripts/codex-commands security-audit-local