-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
161 lines (134 loc) · 4.55 KB
/
Copy pathMakefile
File metadata and controls
161 lines (134 loc) · 4.55 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
# Makefile for mcp-graphql-server
# Variables
BINARY_NAME=mcp-graphql-server
VERSION=1.0.0
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
GIT_COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.GitCommit=$(GIT_COMMIT)"
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Build directories
BUILD_DIR=build
DIST_DIR=dist
.PHONY: all build clean test deps fmt vet lint run help
# Default target
all: clean deps fmt vet test build
# Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/mcp-graphql-server
# Build for multiple platforms
build-all:
@echo "Building for multiple platforms..."
@mkdir -p $(DIST_DIR)
# Linux AMD64
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/mcp-graphql-server
# Linux ARM64
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/mcp-graphql-server
# macOS AMD64
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/mcp-graphql-server
# macOS ARM64
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/mcp-graphql-server
# Windows AMD64
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/mcp-graphql-server
@echo "Build completed. Binaries are in $(DIST_DIR)/"
# Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
@rm -rf $(BUILD_DIR)
@rm -rf $(DIST_DIR)
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
# Run tests with coverage
test-coverage: test
@echo "Generating coverage report..."
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Download dependencies
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Format code
fmt:
@echo "Formatting code..."
$(GOCMD) fmt ./...
# Run go vet
vet:
@echo "Running go vet..."
$(GOCMD) vet ./...
# Run golangci-lint (if available)
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not found, skipping..."; \
fi
# Run the server (for development)
run:
@echo "Running server..."
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/mcp-graphql-server
@GRAPHQL_ENDPOINT=https://api.example.com/graphql $(BUILD_DIR)/$(BINARY_NAME)
# Run with example config
run-example:
@echo "Running server with example config..."
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/mcp-graphql-server
@GRAPHQL_ENDPOINT=https://api.example.com/graphql GRAPHQL_X_API_KEY=example-key $(BUILD_DIR)/$(BINARY_NAME)
# Install the binary to GOPATH/bin
install:
@echo "Installing $(BINARY_NAME)..."
$(GOBUILD) $(LDFLAGS) -o $(GOPATH)/bin/$(BINARY_NAME) ./cmd/mcp-graphql-server
# Create a release package
release: build-all
@echo "Creating release packages..."
@cd $(DIST_DIR) && \
for binary in $(BINARY_NAME)-*; do \
if [[ $$binary == *".exe" ]]; then \
tar -czf $${binary%.exe}.tar.gz $$binary; \
else \
tar -czf $$binary.tar.gz $$binary; \
fi \
done
@echo "Release packages created in $(DIST_DIR)/"
# Docker build
docker-build:
@echo "Building Docker image..."
docker build -t $(BINARY_NAME):$(VERSION) .
docker build -t $(BINARY_NAME):latest .
# Docker run
docker-run:
@echo "Running Docker container..."
docker run --rm -it \
-e GRAPHQL_ENDPOINT=https://api.example.com/graphql \
-e GRAPHQL_X_API_KEY=example-key \
$(BINARY_NAME):latest
# Show help
help:
@echo "Available targets:"
@echo " all - Clean, deps, fmt, vet, test, build"
@echo " build - Build the binary"
@echo " build-all - Build for multiple platforms"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " test-coverage- Run tests with coverage report"
@echo " deps - Download dependencies"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " lint - Run golangci-lint"
@echo " run - Run the server (development)"
@echo " run-example - Run with example config"
@echo " install - Install binary to GOPATH/bin"
@echo " release - Create release packages"
@echo " docker-build - Build Docker image"
@echo " docker-run - Run Docker container"
@echo " help - Show this help"