-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
216 lines (176 loc) · 6.23 KB
/
Makefile
File metadata and controls
216 lines (176 loc) · 6.23 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
# Azure-API-MCP Makefile
# Provides convenience targets for development, building, testing, and releasing
SHELL := /usr/bin/env bash
SHELLFLAGS := -eo pipefail -c
# Variables
BINARY_NAME = azure-api-mcp
MAIN_PATH = ./cmd/server
DOCKER_IMAGE = azure-api-mcp
DOCKER_TAG ?= latest
# Version information
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
GIT_TREE_STATE ?= $(shell if git diff --quiet 2>/dev/null; then echo "clean"; else echo "dirty"; fi)
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go build flags with version injection
LDFLAGS = -ldflags "\
-X github.com/Azure/azure-api-mcp/internal/version.GitVersion=$(VERSION) \
-X github.com/Azure/azure-api-mcp/internal/version.GitCommit=$(GIT_COMMIT) \
-X github.com/Azure/azure-api-mcp/internal/version.GitTreeState=$(GIT_TREE_STATE) \
-X github.com/Azure/azure-api-mcp/internal/version.BuildMetadata=$(BUILD_DATE)"
# Build options
BUILD_FLAGS = -trimpath
CGO_ENABLED ?= 0
# Platform targets for cross-compilation
PLATFORMS = \
linux/amd64 \
linux/arm64 \
darwin/amd64 \
darwin/arm64 \
windows/amd64 \
windows/arm64
# Default target
.DEFAULT_GOAL := help
##@ Development
.PHONY: deps
deps: ## Download and verify dependencies
@echo "==> Downloading dependencies..."
go mod download
go mod verify
.PHONY: build
build: deps ## Build the binary
@echo "==> Building $(BINARY_NAME)..."
CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) $(LDFLAGS) -o $(BINARY_NAME) $(MAIN_PATH)
.PHONY: install
install: ## Install the binary to GOBIN
@echo "==> Installing $(BINARY_NAME)..."
CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) $(LDFLAGS) $(MAIN_PATH)
.PHONY: clean
clean: ## Clean build artifacts
@echo "==> Cleaning build artifacts..."
rm -f $(BINARY_NAME)
rm -rf dist/
rm -rf bin/
rm -f coverage.txt
go clean -cache
docker image rm -f $(DOCKER_IMAGE):$(DOCKER_TAG) 2>/dev/null || true
.PHONY: inspector
inspector: ## Run MCP inspector for debugging
@echo "Running in inspector for debugging..."
npx @modelcontextprotocol/inspector go run ./cmd/server
##@ Testing
.PHONY: test
test: ## Run tests
@echo "==> Running tests..."
go test ./...
.PHONY: test-race
test-race: ## Run tests with race detection
@echo "==> Running tests with race detection..."
go test -race ./...
.PHONY: test-coverage
test-coverage: ## Run tests with coverage
@echo "==> Running tests with coverage..."
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
.PHONY: test-verbose
test-verbose: ## Run tests in verbose mode
@echo "==> Running tests (verbose)..."
go test -v ./...
##@ Code Quality
.PHONY: fmt
fmt: ## Format code
@echo "==> Formatting code..."
go fmt ./...
.PHONY: vet
vet: ## Run go vet
@echo "==> Running go vet..."
go vet ./...
.PHONY: lint
lint: ## Run golangci-lint
@echo "==> Running golangci-lint..."
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "golangci-lint not found. Installing..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@$$(go env GOPATH)/bin/golangci-lint run --timeout=5m
.PHONY: lint-fix
lint-fix: ## Run golangci-lint with auto-fix
@echo "==> Running golangci-lint with auto-fix..."
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "golangci-lint not found. Installing..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@$$(go env GOPATH)/bin/golangci-lint run --fix --timeout=5m
.PHONY: staticcheck
staticcheck: ## Run staticcheck
@echo "==> Running staticcheck..."
@if ! command -v staticcheck >/dev/null 2>&1; then \
echo "staticcheck not found. Installing..."; \
go install honnef.co/go/tools/cmd/staticcheck@latest; \
fi
@$$(go env GOPATH)/bin/staticcheck ./...
##@ Docker
.PHONY: docker-build
docker-build: ## Build Docker image
@echo "==> Building Docker image..."
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg GIT_TREE_STATE=$(GIT_TREE_STATE) \
-t $(DOCKER_IMAGE):$(DOCKER_TAG) .
.PHONY: docker-run
docker-run: docker-build ## Run Docker container
@echo "==> Running Docker container..."
docker run --rm -p 8000:8000 $(DOCKER_IMAGE):$(DOCKER_TAG)
.PHONY: docker-shell
docker-shell: docker-build ## Run Docker container with shell access
@echo "==> Running Docker container with shell..."
docker run --rm -it --entrypoint=/bin/bash $(DOCKER_IMAGE):$(DOCKER_TAG)
##@ Release
.PHONY: release
release: clean ## Build for all platforms
@echo "==> Building for all platforms..."
@mkdir -p dist
@for platform in $(PLATFORMS); do \
GOOS=$$(echo $$platform | cut -d'/' -f1); \
GOARCH=$$(echo $$platform | cut -d'/' -f2); \
output_name=$(BINARY_NAME)-$$GOOS-$$GOARCH; \
if [ "$$GOOS" = "windows" ]; then \
output_name="$$output_name.exe"; \
fi; \
echo "Building for $$GOOS/$$GOARCH..."; \
CGO_ENABLED=$(CGO_ENABLED) GOOS=$$GOOS GOARCH=$$GOARCH \
go build $(BUILD_FLAGS) $(LDFLAGS) -o dist/$$output_name $(MAIN_PATH); \
done
.PHONY: checksums
checksums: release ## Generate checksums for release binaries
@echo "==> Generating checksums..."
@cd dist && sha256sum * > checksums.txt
##@ Verification
.PHONY: check
check: fmt vet staticcheck test ## Run all checks (format, vet, staticcheck, test)
.PHONY: ci
ci: check test-coverage ## Run CI pipeline locally
##@ Utilities
.PHONY: version
version: ## Show version information
@echo "Version: $(VERSION)"
@echo "Git Commit: $(GIT_COMMIT)"
@echo "Git Tree State: $(GIT_TREE_STATE)"
@echo "Build Date: $(BUILD_DATE)"
.PHONY: info
info: ## Show build information
@echo "Shell: $(SHELL) $(SHELLFLAGS)"
@echo "Binary Name: $(BINARY_NAME)"
@echo "Main Path: $(MAIN_PATH)"
@echo "Docker Image: $(DOCKER_IMAGE):$(DOCKER_TAG)"
@echo "CGO Enabled: $(CGO_ENABLED)"
@echo "LDFLAGS: $(LDFLAGS)"
.PHONY: run
run: build ## Build and run the application with --help
@echo "==> Running $(BINARY_NAME)..."
./$(BINARY_NAME) --help
##@ Help
.PHONY: help
help: ## Display this help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)