-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
247 lines (210 loc) · 7.35 KB
/
Makefile
File metadata and controls
247 lines (210 loc) · 7.35 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
# OpenWatch Admin (owadm) Build Configuration
# Unified container management utility
# Build variables
APP_NAME := owadm
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
# Go build variables
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
GO_VERSION := $(shell go version | cut -d ' ' -f 3)
# Build flags
LDFLAGS := -ldflags "-s -w \
-X github.com/hanalyx/openwatch/internal/owadm/cmd.Version=$(VERSION) \
-X github.com/hanalyx/openwatch/internal/owadm/cmd.Commit=$(COMMIT) \
-X github.com/hanalyx/openwatch/internal/owadm/cmd.BuildTime=$(BUILD_TIME)"
# Directories
BIN_DIR := bin
DIST_DIR := dist
MAIN_FILE := cmd/owadm/main.go
# Default target
.DEFAULT_GOAL := build
# Build for current platform
.PHONY: build
build: clean
@echo "Building $(APP_NAME) for $(GOOS)/$(GOARCH)..."
@mkdir -p $(BIN_DIR)
CGO_ENABLED=0 go build $(LDFLAGS) -o $(BIN_DIR)/$(APP_NAME) $(MAIN_FILE)
@echo "[OK] Built $(BIN_DIR)/$(APP_NAME)"
# Build for all platforms
.PHONY: build-all
build-all: clean
@echo "Building $(APP_NAME) for all platforms..."
@mkdir -p $(DIST_DIR)
# Linux AMD64
@echo " Building for linux/amd64..."
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-linux-amd64 $(MAIN_FILE)
# Linux ARM64
@echo " Building for linux/arm64..."
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-linux-arm64 $(MAIN_FILE)
# macOS AMD64 (Intel)
@echo " Building for darwin/amd64..."
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-darwin-amd64 $(MAIN_FILE)
# macOS ARM64 (M1/M2)
@echo " Building for darwin/arm64..."
GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-darwin-arm64 $(MAIN_FILE)
# Windows AMD64
@echo " Building for windows/amd64..."
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build $(LDFLAGS) -o $(DIST_DIR)/$(APP_NAME)-windows-amd64.exe $(MAIN_FILE)
@echo "[OK] Built all platform binaries in $(DIST_DIR)/"
@ls -la $(DIST_DIR)/
# Install locally
.PHONY: install
install: build
@echo "Installing $(APP_NAME) to /usr/local/bin..."
sudo cp $(BIN_DIR)/$(APP_NAME) /usr/local/bin/$(APP_NAME)
sudo chmod +x /usr/local/bin/$(APP_NAME)
@echo "[OK] $(APP_NAME) installed successfully"
@echo "Try: owadm --help"
# Install locally without sudo (to ~/bin)
.PHONY: install-user
install-user: build
@echo "Installing $(APP_NAME) to ~/bin..."
@mkdir -p ~/bin
cp $(BIN_DIR)/$(APP_NAME) ~/bin/$(APP_NAME)
chmod +x ~/bin/$(APP_NAME)
@echo "[OK] $(APP_NAME) installed to ~/bin/"
@echo "Make sure ~/bin is in your PATH"
@echo "Try: owadm --help"
# Development build with race detection
.PHONY: build-dev
build-dev: clean
@echo "Building $(APP_NAME) for development..."
@mkdir -p $(BIN_DIR)
go build -race $(LDFLAGS) -o $(BIN_DIR)/$(APP_NAME)-dev $(MAIN_FILE)
@echo "[OK] Built $(BIN_DIR)/$(APP_NAME)-dev"
# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test -v ./...
@echo "[OK] Tests completed"
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "[OK] Coverage report generated: coverage.html"
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
gofmt -s -w .
go mod tidy
@echo "[OK] Code formatted"
# Lint code
.PHONY: lint
lint:
@echo "Linting code..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
@echo "[WARNING] golangci-lint not installed, using go vet..."; \
go vet ./...; \
fi
@echo "[OK] Linting completed"
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
rm -rf $(BIN_DIR) $(DIST_DIR)
rm -f coverage.out coverage.html
@echo "[OK] Clean completed"
# Show build info
.PHONY: info
info:
@echo "Build Information:"
@echo " App Name: $(APP_NAME)"
@echo " Version: $(VERSION)"
@echo " Commit: $(COMMIT)"
@echo " Go Version: $(GO_VERSION)"
@echo " Target OS: $(GOOS)"
@echo " Target Arch: $(GOARCH)"
@echo " Build Time: $(BUILD_TIME)"
# Development workflow
.PHONY: dev
dev: fmt lint test build
@echo "[OK] Development build completed"
# Release workflow
.PHONY: release
release: fmt lint test build-all
@echo "[OK] Release build completed"
@echo "Binaries available in $(DIST_DIR)/"
# Package management
.PHONY: package-rpm
package-rpm: build
@echo "Building RPM package..."
cd packaging/rpm && ./build-rpm.sh
@echo "[OK] RPM package build completed"
.PHONY: package-deb
package-deb: build
@echo "Building DEB package..."
cd packaging/deb && ./build-deb.sh
@echo "[OK] DEB package build completed"
.PHONY: package-all
package-all: package-rpm package-deb
@echo "[OK] All packages built successfully"
# Quick start for new users
.PHONY: quick-start
quick-start: build install
@echo ""
@echo "owadm is ready!"
@echo ""
@echo "Quick start commands:"
@echo " owadm start # Start OpenWatch"
@echo " owadm status # Check status"
@echo " owadm stop # Stop services"
@echo " owadm --help # Show help"
@echo ""
# -------------------------------------------------------------------
# Python / Backend Quality Targets
# -------------------------------------------------------------------
.PHONY: py-lint py-format py-test py-coverage py-specs py-check
py-lint:
cd backend && black --check app/ --line-length 120
cd backend && flake8 app/ --max-line-length=120 --extend-ignore=E203,W503 --per-file-ignores='__init__.py:F401,E402'
cd backend && mypy app/ --ignore-missing-imports
py-format:
cd backend && black app/ --line-length 120
cd backend && isort app/ --profile black --line-length 120
py-test:
cd backend && pytest ../tests/backend/ -x --timeout=30 -q
py-coverage:
cd backend && pytest ../tests/backend/ --cov=app --cov-report=term --cov-fail-under=42
py-specs:
python3 scripts/validate-specs.py
python3 scripts/check-spec-coverage.py --enforce-active
py-check: py-lint py-test py-specs
@echo "All Python checks pass"
# Help
.PHONY: help
help:
@echo "OpenWatch Admin (owadm) Build System"
@echo ""
@echo "Available targets:"
@echo " build Build for current platform"
@echo " build-all Build for all platforms"
@echo " build-dev Build with race detection"
@echo " install Install to /usr/local/bin (requires sudo)"
@echo " install-user Install to ~/bin"
@echo " test Run tests"
@echo " test-coverage Run tests with coverage report"
@echo " fmt Format code"
@echo " lint Lint code"
@echo " clean Clean build artifacts"
@echo " dev Run development workflow"
@echo " release Run release workflow"
@echo " quick-start Build and install for new users"
@echo " info Show build information"
@echo ""
@echo "Python / Backend targets:"
@echo " py-lint Lint Python backend (black, flake8, mypy)"
@echo " py-format Format Python backend (black, isort)"
@echo " py-test Run backend tests"
@echo " py-coverage Run backend tests with coverage"
@echo " py-specs Validate specs and AC coverage"
@echo " py-check Run all Python checks"
@echo ""
@echo " help Show this help message"