-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathMakefile
More file actions
311 lines (291 loc) · 11.5 KB
/
Makefile
File metadata and controls
311 lines (291 loc) · 11.5 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
.PHONY: build lint test test-unit test-integration test-all test-serena test-serena-gateway coverage test-ci format clean install release help agent-finished
# Default target
.DEFAULT_GOAL := help
# Binary name
BINARY_NAME=awmg
# Go and toolchain versions
GO_VERSION=1.25.0
GOLANGCI_LINT_VERSION=v2.8.0
# Build the CLI binary
build:
@echo "Building $(BINARY_NAME)..."
@go mod tidy
@go build -o $(BINARY_NAME) .
@echo "Build complete: $(BINARY_NAME)"
# Run all linters
lint:
@echo "Running linters..."
@go mod tidy
@go vet ./...
@echo "Running gofmt check..."
@test -z "$$(gofmt -l .)" || (echo "The following files are not formatted:"; gofmt -l .; exit 1)
@echo "Running golangci-lint..."
@GOPATH=$$(go env GOPATH); \
if [ -f "$$GOPATH/bin/golangci-lint" ]; then \
$$GOPATH/bin/golangci-lint run --timeout=5m || echo "⚠ Warning: golangci-lint failed (compatibility issue with Go 1.25.0). Continuing with other checks..."; \
elif command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run --timeout=5m || echo "⚠ Warning: golangci-lint failed (compatibility issue with Go 1.25.0). Continuing with other checks..."; \
else \
echo "⚠ Warning: golangci-lint not found. Run 'make install' to install it."; \
echo " Skipping golangci-lint checks..."; \
fi
@echo "Linting complete!"
# Run unit tests only (no build required)
test-unit:
@echo "Running unit tests..."
@go mod tidy
@go test -v ./internal/...
# Run all tests (unit + integration)
test-all:
@echo "Running all tests..."
@go mod tidy
@go test -v ./...
# Legacy target: run unit tests (for backward compatibility)
test: test-unit
# Run binary integration tests (requires built binary)
test-integration:
@echo "Running binary integration tests..."
@if [ ! -f $(BINARY_NAME) ]; then \
echo "Binary not found. Building..."; \
$(MAKE) build; \
fi
@go test -v ./test/integration/...
# Run format, build, lint, and all tests (for agents before completion)
# Optimized: single go mod tidy, no redundant clean/vet/gofmt-check
agent-finished:
@echo "Running agent-finished checks..."
@echo ""
@go mod tidy
@echo "Formatting Go code..."
@gofmt -w .
@echo "Formatting complete!"
@echo ""
@echo "Building $(BINARY_NAME)..."
@go build -o $(BINARY_NAME) .
@echo "Build complete: $(BINARY_NAME)"
@echo ""
@echo "Running linters..."
@go vet ./...
@echo "Running golangci-lint..."
@GOPATH=$$(go env GOPATH); \
if [ -f "$$GOPATH/bin/golangci-lint" ]; then \
$$GOPATH/bin/golangci-lint run --timeout=5m || echo "⚠ Warning: golangci-lint failed (compatibility issue with Go 1.25.0). Continuing with other checks..."; \
elif command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run --timeout=5m || echo "⚠ Warning: golangci-lint failed (compatibility issue with Go 1.25.0). Continuing with other checks..."; \
else \
echo "⚠ Warning: golangci-lint not found. Run 'make install' to install it."; \
echo " Skipping golangci-lint checks..."; \
fi
@echo "Linting complete!"
@echo ""
@echo "Running all tests..."
@go test ./...
@echo ""
@echo "✓ All agent-finished checks passed!"
# Run unit tests with coverage
coverage:
@echo "Running unit tests with coverage..."
@go test -coverprofile=coverage.out ./internal/... 2>&1 | grep -vE "go: no such tool \"covdata\"|no such tool" | grep -v "^$$" || true
@echo ""
@echo "Coverage report:"
@if [ -f coverage.out ]; then \
go tool cover -func=coverage.out 2>/dev/null || echo "Note: go tool cover not available, but coverage data was collected"; \
else \
echo "Error: coverage.out not generated"; \
exit 1; \
fi
@echo ""
@echo "Coverage profile saved to coverage.out"
@echo "To view HTML coverage report, run: go tool cover -html=coverage.out"
# Run Serena MCP Server tests (direct connection)
test-serena:
@echo "Running Serena MCP Server tests (direct connection)..."
@cd test/serena-mcp-tests && ./test_serena.sh
@echo ""
@echo "Test results saved to test/serena-mcp-tests/results/"
@echo "For detailed analysis, see test/serena-mcp-tests/TEST_REPORT.md"
# Run Serena MCP Server tests through MCP Gateway
test-serena-gateway:
@echo "Running Serena MCP Server tests (via MCP Gateway)..."
@cd test/serena-mcp-tests && ./test_serena_via_gateway.sh
@echo ""
@echo "Test results saved to test/serena-mcp-tests/results-gateway/"
@echo "Compare with direct connection results in test/serena-mcp-tests/results/"
# Run unit tests with coverage and JSON output for CI
test-ci:
@echo "Running unit tests with coverage and JSON output..."
@go mod tidy
@go test -v -parallel=8 -timeout=3m -coverprofile=coverage.out -json ./internal/... | tee test-result-unit.json
@echo "Test results saved to test-result-unit.json"
@echo "Coverage profile saved to coverage.out"
# Format Go code
format:
@echo "Formatting Go code..."
@gofmt -w .
@echo "Formatting complete!"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -f $(BINARY_NAME)
@rm -f coverage.out
@rm -f test-result-unit.json
@go mod tidy
@go clean
@echo "Clean complete!"
# Trigger the release workflow via workflow_dispatch
release:
@echo "Triggering release workflow..."
@# Check if first argument is provided
@if [ -z "$(filter-out $@,$(MAKECMDGOALS))" ]; then \
echo "Error: Bump type is required. Usage: make release patch|minor|major"; \
exit 1; \
fi
@BUMP_TYPE="$(filter-out $@,$(MAKECMDGOALS))"; \
if ! echo "$$BUMP_TYPE" | grep -qE '^(patch|minor|major)$$'; then \
echo "Error: Bump type must be one of: patch, minor, major"; \
exit 1; \
fi; \
echo "Bump type: $$BUMP_TYPE"; \
echo ""; \
echo "Fetching latest changes from remote..."; \
git pull || { echo "Error: Failed to pull latest changes"; exit 1; }; \
git fetch --tags --force || { echo "Error: Failed to fetch tags"; exit 1; }; \
echo "✓ Latest changes and tags fetched"; \
echo ""; \
echo "Checking for uncommitted changes..."; \
if [ -n "$$(git status --porcelain)" ]; then \
echo "Error: You have uncommitted changes. Please commit or stash them before creating a release."; \
git status --short; \
exit 1; \
fi; \
echo "✓ Working directory is clean"; \
echo ""; \
LATEST_TAG=$$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -1); \
if [ -z "$$LATEST_TAG" ]; then \
NEXT_VERSION="v0.0.1"; \
if [ "$$BUMP_TYPE" = "minor" ]; then \
NEXT_VERSION="v0.1.0"; \
elif [ "$$BUMP_TYPE" = "major" ]; then \
NEXT_VERSION="v1.0.0"; \
fi; \
echo "No existing tags found, will create: $$NEXT_VERSION"; \
else \
echo "Latest tag: $$LATEST_TAG"; \
VERSION_NUM=$$(echo $$LATEST_TAG | sed 's/^v//'); \
MAJOR=$$(echo $$VERSION_NUM | cut -d. -f1); \
MINOR=$$(echo $$VERSION_NUM | cut -d. -f2); \
PATCH=$$(echo $$VERSION_NUM | cut -d. -f3); \
if [ "$$BUMP_TYPE" = "major" ]; then \
MAJOR=$$((MAJOR + 1)); \
MINOR=0; \
PATCH=0; \
elif [ "$$BUMP_TYPE" = "minor" ]; then \
MINOR=$$((MINOR + 1)); \
PATCH=0; \
elif [ "$$BUMP_TYPE" = "patch" ]; then \
PATCH=$$((PATCH + 1)); \
fi; \
NEXT_VERSION="v$$MAJOR.$$MINOR.$$PATCH"; \
echo "Next version will be: $$NEXT_VERSION"; \
fi; \
echo ""; \
printf "Do you want to trigger the release workflow? [Y/n] "; \
read -r CONFIRM; \
CONFIRM=$${CONFIRM:-Y}; \
if [ "$$CONFIRM" != "Y" ] && [ "$$CONFIRM" != "y" ]; then \
echo "Release cancelled."; \
exit 1; \
fi; \
echo "Triggering release workflow with type: $$BUMP_TYPE"; \
echo ""; \
if ! command -v gh >/dev/null 2>&1; then \
echo "Error: 'gh' CLI is not installed. Please install it from https://cli.github.com/"; \
echo ""; \
echo "Alternative: Manually trigger the workflow at:"; \
echo " https://github.com/github/gh-aw-mcpg/actions/workflows/release.lock.yml"; \
echo " Select 'Run workflow' and choose release type: $$BUMP_TYPE"; \
exit 1; \
fi; \
gh workflow run release.lock.yml --ref main -f release_type=$$BUMP_TYPE || { \
echo ""; \
echo "Error: Failed to trigger workflow. Please check:"; \
echo " 1. You are authenticated with 'gh auth login'"; \
echo " 2. You have permission to trigger workflows"; \
echo ""; \
echo "Alternative: Manually trigger the workflow at:"; \
echo " https://github.com/github/gh-aw-mcpg/actions/workflows/release.lock.yml"; \
exit 1; \
}; \
echo "✓ Release workflow triggered successfully"; \
echo ""; \
echo "The workflow will:"; \
echo " 1. Run tests to ensure everything passes"; \
echo " 2. Create and push tag: $$NEXT_VERSION"; \
echo " 3. Build multi-platform binaries"; \
echo " 4. Build and push Docker containers"; \
echo " 5. Generate SBOMs"; \
echo " 6. Create GitHub release with artifacts"; \
echo ""; \
echo "Monitor the release workflow at:"; \
echo " https://github.com/github/gh-aw-mcpg/actions/workflows/release.lock.yml"
# Prevent make from treating the argument as a target
%:
@:
# Install required toolchains
install:
@echo "Installing required toolchains..."
@echo "Checking Go installation..."
@if command -v go >/dev/null 2>&1; then \
INSTALLED_VERSION=$$(go version | awk '{print $$3}' | sed 's/go//'); \
echo "✓ Go $$INSTALLED_VERSION is installed"; \
if [ "$$INSTALLED_VERSION" != "$(GO_VERSION)" ]; then \
echo "⚠ Warning: Expected Go $(GO_VERSION), but found $$INSTALLED_VERSION"; \
echo " Visit https://go.dev/dl/ to install Go $(GO_VERSION)"; \
fi; \
else \
echo "✗ Go is not installed"; \
echo " Visit https://go.dev/dl/ to install Go $(GO_VERSION)"; \
exit 1; \
fi
@echo ""
@echo "Checking golangci-lint installation..."
@GOPATH=$$(go env GOPATH); \
if [ -f "$$GOPATH/bin/golangci-lint" ] || command -v golangci-lint >/dev/null 2>&1; then \
if [ -f "$$GOPATH/bin/golangci-lint" ]; then \
INSTALLED_LINT_VERSION=$$($$GOPATH/bin/golangci-lint version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "unknown"); \
else \
INSTALLED_LINT_VERSION=$$(golangci-lint version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "unknown"); \
fi; \
echo "✓ golangci-lint v$$INSTALLED_LINT_VERSION is installed"; \
else \
echo "✗ golangci-lint is not installed"; \
echo " Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$GOPATH/bin $(GOLANGCI_LINT_VERSION); \
echo "✓ golangci-lint $(GOLANGCI_LINT_VERSION) installed"; \
fi
@echo ""
@echo "Installing Go dependencies..."
@go mod download
@go mod verify
@echo "✓ Dependencies installed and verified"
@echo ""
@echo "✓ Toolchain installation complete!"
# Display help information
help:
@echo "Available targets:"
@echo " build - Build the CLI binary"
@echo " lint - Run all linters (go vet, gofmt check, golangci-lint)"
@echo " test - Run unit tests (no build required)"
@echo " test-unit - Run unit tests (no build required)"
@echo " test-integration - Run binary integration tests (requires built binary)"
@echo " test-all - Run all tests (unit + integration)"
@echo " test-serena - Run Serena MCP Server tests (direct connection)"
@echo " test-serena-gateway - Run Serena MCP Server tests (via MCP Gateway)"
@echo " coverage - Run unit tests with coverage report"
@echo " test-ci - Run unit tests with coverage and JSON output for CI"
@echo " format - Format Go code using gofmt"
@echo " clean - Clean build artifacts"
@echo " install - Install required toolchains and dependencies"
@echo " release - Trigger the release workflow (usage: make release patch|minor|major)"
@echo " agent-finished - Run format, build, lint, and all tests (for agents before completion)"
@echo " help - Display this help message"