-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
332 lines (305 loc) · 9.87 KB
/
Makefile
File metadata and controls
332 lines (305 loc) · 9.87 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
.PHONY: help build run dev test test-verbose clean install stop start restart lint fmt vet
# Default target
help:
@echo "Blockbusterr - Makefile Commands"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Build Commands:"
@echo " build Build the application binary"
@echo " install Install dependencies"
@echo " clean Remove build artifacts"
@echo ""
@echo "Run Commands:"
@echo " run Build and run the application"
@echo " dev Run the application (assumes already built)"
@echo " start Start the application in background"
@echo " stop Stop the application"
@echo " restart Restart the application"
@echo ""
@echo "Test Commands:"
@echo " test Run all tests"
@echo " test-verbose Run all tests with verbose output"
@echo " test-coverage Run tests with coverage report"
@echo ""
@echo "Code Quality:"
@echo " lint Run linter"
@echo " fmt Format code"
@echo " vet Run go vet"
@echo " check Run fmt, vet, and lint"
@echo ""
@echo "Docker Commands:"
@echo " docker-build Build Docker image"
@echo " docker-run Run Docker container"
@echo " beta-fast Build and push beta (amd64 only - fast, use for testing)"
@echo " beta Build and push beta (multi-platform - slow, use for releases)"
@echo " beta-test Pull and run latest beta version locally"
@echo ""
# Build the application
build:
@echo "Building blockbusterr..."
@go build -o bin/blockbusterr cmd/app/main.go
@echo "✓ Build complete: bin/blockbusterr"
# Install dependencies
install:
@echo "Installing dependencies..."
@go mod download
@go mod tidy
@echo "✓ Dependencies installed"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf bin/
@go clean
@echo "✓ Clean complete"
# Build and run the application
run: build
@echo "Starting blockbusterr..."
@./bin/blockbusterr
# Run the application (assumes already built)
dev:
go run cmd/app/main.go
# Start the application in background
start: build stop
@echo "Starting blockbusterr in background..."
@nohup ./bin/blockbusterr > blockbusterr.log 2>&1 &
@sleep 2
@if lsof -ti:9090 > /dev/null 2>&1; then \
echo "✓ Blockbusterr started on http://127.0.0.1:9090"; \
echo " Logs: tail -f blockbusterr.log"; \
else \
echo "✗ Failed to start blockbusterr"; \
tail -20 blockbusterr.log; \
exit 1; \
fi
# Stop the application
stop:
@echo "Stopping blockbusterr..."
@if lsof -ti:9090 > /dev/null 2>&1; then \
lsof -ti:9090 | xargs kill -9; \
echo "✓ Blockbusterr stopped"; \
else \
echo "✓ Blockbusterr not running"; \
fi
# Restart the application
restart: stop start
# Run all tests
test:
@echo "Running tests..."
@go test ./... -v
# Run tests with verbose output
test-verbose:
@echo "Running tests (verbose)..."
@go test -v ./...
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
@go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "✓ Coverage report generated: coverage.html"
# Run tests for a specific package
test-pkg:
@if [ -z "$(PKG)" ]; then \
echo "Usage: make test-pkg PKG=<package>"; \
echo "Example: make test-pkg PKG=./internal/scoring"; \
exit 1; \
fi
@echo "Running tests for $(PKG)..."
@go test -v $(PKG)
# Format code
fmt:
@echo "Formatting code..."
@go fmt ./...
@echo "✓ Code formatted"
# Run go vet
vet:
@echo "Running go vet..."
@go vet ./...
@echo "✓ Vet complete"
# Run linter (requires golangci-lint)
lint:
@echo "Running linter..."
@if command -v golangci-lint > /dev/null; then \
golangci-lint run ./...; \
echo "✓ Lint complete"; \
else \
echo "⚠ golangci-lint not installed"; \
echo "Install: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Run all checks
check: fmt vet
@echo "✓ All checks passed"
# Build for production
build-prod:
@echo "Building for production..."
@CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o bin/blockbusterr cmd/app/main.go
@echo "✓ Production build complete"
# Show application status
status:
@if lsof -ti:9090 > /dev/null 2>&1; then \
echo "✓ Blockbusterr is running"; \
echo " PID: $$(lsof -ti:9090)"; \
echo " URL: http://127.0.0.1:9090"; \
else \
echo "✗ Blockbusterr is not running"; \
fi
# Show logs
logs:
@if [ -f blockbusterr.log ]; then \
tail -f blockbusterr.log; \
else \
echo "No log file found. Application may not be running in background."; \
fi
# Docker commands (if using Docker)
docker-build:
@echo "Building Docker image..."
@docker build -t blockbusterr:latest .
@echo "✓ Docker image built"
docker-run:
@echo "Running Docker container..."
@docker run -p 9090:9090 -v $(PWD)/data:/app/data -v $(PWD)/config:/app/config blockbusterr:latest
# Beta test - pull and run latest beta version locally
# Usage: make beta-test VERSION=v1.2.0
beta-test:
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make beta-test VERSION=v1.2.0"; \
echo "Example: make beta-test VERSION=v1.2.0"; \
exit 1; \
fi
@echo "🔍 Finding latest beta version for $(VERSION)..."
@LATEST_BETA=$$(git tag -l "$(VERSION)-beta.*" | sort -V | tail -n 1); \
if [ -z "$$LATEST_BETA" ]; then \
echo "❌ No beta versions found for $(VERSION)"; \
exit 1; \
fi; \
echo " Latest beta: $$LATEST_BETA"; \
echo ""; \
echo "🗑️ Removing existing container..."; \
docker rm -f blockbusterr 2>/dev/null || true; \
echo ""; \
echo "🚀 Starting $$LATEST_BETA..."; \
docker run -d \
--name blockbusterr \
-p 9090:9090 \
-v ~/blockbusterr-data:/app/data \
ghcr.io/mahcks/blockbusterr:$$LATEST_BETA; \
if [ $$? -eq 0 ]; then \
echo ""; \
echo "✅ Container started successfully!"; \
echo " Version: $$LATEST_BETA"; \
echo " URL: http://localhost:9090"; \
echo ""; \
echo "📝 Useful commands:"; \
echo " Logs: docker logs -f blockbusterr"; \
echo " Stop: docker stop blockbusterr"; \
else \
echo ""; \
echo "❌ Failed to start container!"; \
exit 1; \
fi
# Fast beta build (amd64 only, much faster for testing)
# Usage: make beta-fast VERSION=v1.2.0
beta-fast:
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make beta-fast VERSION=v1.2.0"; \
echo "Example: make beta-fast VERSION=v1.2.0"; \
exit 1; \
fi
@echo "🔄 Fetching latest tags from GitHub..."
@git fetch --tags --quiet 2>/dev/null || true
@echo "🔍 Finding latest beta version for $(VERSION)..."
@LATEST_BETA=$$(git tag -l "$(VERSION)-beta.*" | sort -V | tail -n 1); \
if [ -z "$$LATEST_BETA" ]; then \
NEXT_BETA="$(VERSION)-beta.1"; \
echo " No existing beta tags found. Starting at $$NEXT_BETA"; \
else \
BETA_NUM=$$(echo $$LATEST_BETA | sed 's/.*-beta\.\([0-9]*\)/\1/'); \
NEXT_NUM=$$((BETA_NUM + 1)); \
NEXT_BETA="$(VERSION)-beta.$$NEXT_NUM"; \
echo " Latest beta: $$LATEST_BETA"; \
echo " Next beta: $$NEXT_BETA"; \
fi; \
echo ""; \
echo "📦 Building Docker image (amd64 only - fast build)..."; \
COMMIT=$$(git rev-parse HEAD); \
docker buildx build \
--build-arg VERSION=$$NEXT_BETA \
--build-arg COMMIT=$$COMMIT \
--platform linux/amd64 \
-t ghcr.io/mahcks/blockbusterr:$$NEXT_BETA \
-t ghcr.io/mahcks/blockbusterr:latest-beta \
--push \
.; \
if [ $$? -ne 0 ]; then \
echo ""; \
echo "❌ Build failed!"; \
exit 1; \
fi; \
echo ""; \
echo "✅ Beta release complete!"; \
echo " Version: $$NEXT_BETA"; \
echo " Image: ghcr.io/mahcks/blockbusterr:$$NEXT_BETA"; \
echo " Platform: linux/amd64 only (fast build)"; \
echo ""; \
echo "🏷️ Creating git tag..."; \
git tag $$NEXT_BETA 2>/dev/null || echo " Tag already exists locally"; \
git push origin $$NEXT_BETA 2>/dev/null || echo " Tag already exists on remote"; \
echo ""; \
echo "📝 To test this version:"; \
echo " image: ghcr.io/mahcks/blockbusterr:$$NEXT_BETA"
# Full beta build with multi-platform support (slower, for final releases)
# Usage: make beta VERSION=v1.2.0
beta:
@if [ -z "$(VERSION)" ]; then \
echo "Usage: make beta VERSION=v1.2.0"; \
echo "Example: make beta VERSION=v1.2.0"; \
exit 1; \
fi
@echo "🔄 Fetching latest tags from GitHub..."
@git fetch --tags --quiet 2>/dev/null || true
@echo "🔍 Finding latest beta version for $(VERSION)..."
@LATEST_BETA=$$(git tag -l "$(VERSION)-beta.*" | sort -V | tail -n 1); \
if [ -z "$$LATEST_BETA" ]; then \
NEXT_BETA="$(VERSION)-beta.1"; \
echo " No existing beta tags found. Starting at $$NEXT_BETA"; \
else \
BETA_NUM=$$(echo $$LATEST_BETA | sed 's/.*-beta\.\([0-9]*\)/\1/'); \
NEXT_NUM=$$((BETA_NUM + 1)); \
NEXT_BETA="$(VERSION)-beta.$$NEXT_NUM"; \
echo " Latest beta: $$LATEST_BETA"; \
echo " Next beta: $$NEXT_BETA"; \
fi; \
echo ""; \
echo "📦 Building Docker image (multi-platform - this will take a while)..."; \
COMMIT=$$(git rev-parse HEAD); \
docker buildx build \
--build-arg VERSION=$$NEXT_BETA \
--build-arg COMMIT=$$COMMIT \
--platform linux/amd64,linux/arm64 \
-t ghcr.io/mahcks/blockbusterr:$$NEXT_BETA \
-t ghcr.io/mahcks/blockbusterr:latest-beta \
--push \
.; \
if [ $$? -ne 0 ]; then \
echo ""; \
echo "❌ Build failed!"; \
exit 1; \
fi; \
echo ""; \
echo "✅ Beta release complete!"; \
echo " Version: $$NEXT_BETA"; \
echo " Image: ghcr.io/mahcks/blockbusterr:$$NEXT_BETA"; \
echo " Platforms: linux/amd64, linux/arm64"; \
echo ""; \
echo "🏷️ Creating git tag..."; \
git tag $$NEXT_BETA 2>/dev/null || echo " Tag already exists locally"; \
git push origin $$NEXT_BETA 2>/dev/null || echo " Tag already exists on remote"; \
echo ""; \
echo "📝 To test this version:"; \
echo " image: ghcr.io/mahcks/blockbusterr:$$NEXT_BETA"
# Development workflow
dev-setup: install build
@echo "✓ Development environment ready"
@echo " Run 'make run' to start the application"
# Quick rebuild and restart (useful during development)
quick: build restart