-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
275 lines (246 loc) · 7.95 KB
/
Makefile
File metadata and controls
275 lines (246 loc) · 7.95 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
# NoteDown Makefile
# Builds CLI and VSCode extension for multiple platforms
# Project information
PROJECT_NAME := noted
VERSION := $(shell grep -o '"version": "[^"]*"' vscode-extension/package.json 2>/dev/null | cut -d'"' -f4 || echo "3.14.15")
COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS := -X notedown/cmd/noted/cmd.Version=$(VERSION) -X notedown/cmd/noted/cmd.CommitHash=$(COMMIT_HASH) -X notedown/cmd/noted/cmd.BuildDate=$(BUILD_DATE)
# Directories
BUILD_DIR := dist
CLI_DIR := cmd/noted
VSCODE_DIR := vscode-extension
DOCS_DIR := docs
# Supported platforms and architectures
PLATFORMS := \
linux/amd64 \
linux/arm64 \
linux/386 \
darwin/amd64 \
darwin/arm64 \
windows/amd64 \
windows/arm64 \
windows/386 \
freebsd/amd64 \
openbsd/amd64
# Default target
.PHONY: all
all: clean build-cli build-vscode
# Clean build directory
.PHONY: clean
clean:
@echo "🧹 Cleaning build directory..."
rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
# Build CLI for current platform only
.PHONY: build
build: clean
@echo "🔨 Building CLI for current platform..."
go build -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(PROJECT_NAME) ./$(CLI_DIR)
@echo "✅ CLI built successfully: $(BUILD_DIR)/$(PROJECT_NAME)"
# Build CLI for all platforms
.PHONY: build-cli
build-cli: clean
@echo "🔨 Building CLI for all platforms..."
@$(foreach platform,$(PLATFORMS), \
$(call build_cli_platform,$(platform)) \
)
@echo "✅ CLI built for all platforms"
# Build VSCode extension
.PHONY: build-vscode
build-vscode:
@echo "🔨 Building VSCode extension..."
cd $(VSCODE_DIR) && npm install
cd $(VSCODE_DIR) && npm run compile
cd $(VSCODE_DIR) && npm run package
@if [ -f $(VSCODE_DIR)/*.vsix ]; then \
mv $(VSCODE_DIR)/*.vsix $(BUILD_DIR)/; \
echo "✅ VSCode extension built successfully"; \
else \
echo "❌ VSCode extension build failed"; \
exit 1; \
fi
# Development build (current platform only)
.PHONY: dev
dev:
@echo "🚀 Building development version..."
go build -race -ldflags "$(LDFLAGS)" -o $(PROJECT_NAME) ./$(CLI_DIR)
@echo "✅ Development build complete: ./$(PROJECT_NAME)"
# Install to system (Unix-like systems)
.PHONY: install
install: build
@echo "📦 Installing to system..."
sudo cp $(BUILD_DIR)/$(PROJECT_NAME) /usr/local/bin/
sudo chmod +x /usr/local/bin/$(PROJECT_NAME)
@echo "✅ Installed to /usr/local/bin/$(PROJECT_NAME)"
# Uninstall from system
.PHONY: uninstall
uninstall:
@echo "🗑️ Uninstalling from system..."
sudo rm -f /usr/local/bin/$(PROJECT_NAME)
@echo "✅ Uninstalled"
# Create GitHub release archives
.PHONY: release
release: build-cli build-vscode
@echo "📦 Creating release archives..."
@$(foreach platform,$(PLATFORMS), \
$(call create_release_archive,$(platform)) \
)
@echo "✅ Release archives created in $(BUILD_DIR)/"
@echo "📋 Release files:"
@ls -la $(BUILD_DIR)/*.tar.gz $(BUILD_DIR)/*.zip 2>/dev/null || true
# Create checksums for release files
.PHONY: checksums
checksums: release
@echo "🔐 Creating checksums..."
cd $(BUILD_DIR) && sha256sum *.tar.gz *.zip *.vsix > checksums.sha256
@echo "✅ Checksums created: $(BUILD_DIR)/checksums.sha256"
# Run tests
.PHONY: test
test:
@echo "🧪 Running Go tests..."
go test -v ./...
@if [ -d $(VSCODE_DIR) ]; then \
echo "🧪 Running VSCode extension tests..."; \
cd $(VSCODE_DIR) && npm test; \
fi
# Run linters
.PHONY: lint
lint:
@echo "🔍 Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "⚠️ golangci-lint not installed, skipping Go linting"; \
fi
@if [ -d $(VSCODE_DIR) ]; then \
echo "🔍 Linting TypeScript..."; \
cd $(VSCODE_DIR) && npm run lint; \
fi
# Format code
.PHONY: fmt
fmt:
@echo "✨ Formatting Go code..."
go fmt ./...
goimports -w .
@if [ -d $(VSCODE_DIR) ]; then \
echo "✨ Formatting TypeScript..."; \
cd $(VSCODE_DIR) && npm run format; \
fi
# Generate documentation
.PHONY: docs
docs:
@echo "📚 Generating documentation..."
@if command -v godoc >/dev/null 2>&1; then \
echo "Go documentation available at: http://localhost:6060/pkg/"; \
echo "Run: godoc -http=:6060"; \
fi
# Setup development environment
.PHONY: setup
setup:
@echo "🔧 Setting up development environment..."
go mod tidy
go mod download
@if [ -d $(VSCODE_DIR) ]; then \
cd $(VSCODE_DIR) && npm install; \
fi
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "📦 Installing golangci-lint..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.54.2; \
fi
@echo "✅ Development environment setup complete"
# Quick test of built binary
.PHONY: test-build
test-build: build
@echo "🧪 Testing built binary..."
./$(BUILD_DIR)/$(PROJECT_NAME) --version
./$(BUILD_DIR)/$(PROJECT_NAME) --help
@echo "✅ Binary test passed"
# Docker build (if Dockerfile exists)
.PHONY: docker
docker:
@if [ -f Dockerfile ]; then \
echo "🐳 Building Docker image..."; \
docker build -t $(PROJECT_NAME):$(VERSION) .; \
docker build -t $(PROJECT_NAME):latest .; \
echo "✅ Docker image built: $(PROJECT_NAME):$(VERSION)"; \
else \
echo "⚠️ No Dockerfile found"; \
fi
# Show build info
.PHONY: info
info:
@echo "📊 Build Information:"
@echo " Project: $(PROJECT_NAME)"
@echo " Version: $(VERSION)"
@echo " Commit: $(COMMIT_HASH)"
@echo " Date: $(BUILD_DATE)"
@echo " Platforms: $(words $(PLATFORMS)) targets"
@echo " Go version: $(shell go version)"
@echo ""
@echo "🎯 Available targets:"
@echo " make build - Build for current platform"
@echo " make build-cli - Build CLI for all platforms"
@echo " make build-vscode - Build VSCode extension"
@echo " make release - Create release archives"
@echo " make checksums - Generate checksums"
@echo " make test - Run tests"
@echo " make lint - Run linters"
@echo " make install - Install to system"
@echo " make clean - Clean build directory"
# Helper function to build CLI for a specific platform
define build_cli_platform
$(eval GOOS := $(word 1,$(subst /, ,$(1))))
$(eval GOARCH := $(word 2,$(subst /, ,$(1))))
$(eval BINARY_NAME := $(PROJECT_NAME)$(if $(filter windows,$(GOOS)),.exe,))
$(eval OUTPUT_DIR := $(BUILD_DIR)/$(GOOS)-$(GOARCH))
@echo " 📦 Building $(GOOS)/$(GOARCH)..."
@mkdir -p $(OUTPUT_DIR)
@GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags "$(LDFLAGS)" \
-o $(OUTPUT_DIR)/$(BINARY_NAME) \
./$(CLI_DIR)
endef
# Helper function to create release archives
define create_release_archive
$(eval GOOS := $(word 1,$(subst /, ,$(1))))
$(eval GOARCH := $(word 2,$(subst /, ,$(1))))
$(eval BINARY_NAME := $(PROJECT_NAME)$(if $(filter windows,$(GOOS)),.exe,))
$(eval OUTPUT_DIR := $(BUILD_DIR)/$(GOOS)-$(GOARCH))
$(eval ARCHIVE_NAME := $(PROJECT_NAME)-$(VERSION)-$(GOOS)-$(GOARCH))
@if [ -f $(OUTPUT_DIR)/$(BINARY_NAME) ]; then \
echo " 📦 Creating archive for $(GOOS)/$(GOARCH)..."; \
cp README.md $(OUTPUT_DIR)/; \
cp LICENSE $(OUTPUT_DIR)/ 2>/dev/null || true; \
if [ -d $(DOCS_DIR) ]; then \
cp -r $(DOCS_DIR) $(OUTPUT_DIR)/; \
fi; \
cd $(BUILD_DIR) && \
if [ "$(GOOS)" = "windows" ]; then \
zip -r $(ARCHIVE_NAME).zip $(GOOS)-$(GOARCH); \
else \
tar -czf $(ARCHIVE_NAME).tar.gz $(GOOS)-$(GOARCH); \
fi; \
fi
endef
# Watch for changes and rebuild (requires entr)
.PHONY: watch
watch:
@if command -v entr >/dev/null 2>&1; then \
echo "👀 Watching for changes... (Ctrl+C to stop)"; \
find . -name "*.go" | entr -r make dev; \
else \
echo "⚠️ entr not installed. Install with: brew install entr (macOS) or apt install entr (Ubuntu)"; \
fi
# Quick development cycle
.PHONY: quick
quick: dev test-build
# Full CI/CD pipeline simulation
.PHONY: ci
ci: clean lint test build-cli build-vscode release checksums
@echo "🎉 CI pipeline completed successfully!"
@echo "📦 Artifacts created:"
@ls -la $(BUILD_DIR)/
# Help target
.PHONY: help
help: info