-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (127 loc) · 4.87 KB
/
Copy pathMakefile
File metadata and controls
148 lines (127 loc) · 4.87 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
.PHONY: all build clean deps test test-e2e e2e-deps test-all test-coverage lint fmt install build-linux dev verify help
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOLINT=golangci-lint
# Binary names
BINARY_NAME=spec-forge
BINARY_UNIX=$(BINARY_NAME)_unix
# Main package
MAIN_PACKAGE=.
# Build directory
BUILD_DIR=./build
# E2E test tool versions (pinned for supply chain security)
GOCTL_VERSION=v1.9.2
PROTOC_GEN_CONNECT_OPENAPI_VERSION=v0.25.5
# All-in-one: clean, deps, format, lint, test, build
all: clean deps fmt lint test build
build:
@echo "Building..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PACKAGE)
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
@echo "Clean complete"
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
@echo "Dependencies downloaded"
test:
@echo "Running tests..."
$(GOTEST) -race -v -coverprofile=coverage.out ./...
@echo "Tests complete"
# Install E2E test dependencies
e2e-deps:
@echo "Installing E2E test dependencies..."
@# Check for protoc (required for gRPC-protoc tests)
@if ! command -v protoc >/dev/null 2>&1; then \
echo "⚠️ WARNING: protoc not found in PATH. gRPC-protoc tests will be skipped."; \
echo " Install protoc from: https://grpc.io/docs/protoc-installation/"; \
fi
@# Check for java (required for Spring Boot tests)
@if ! command -v java >/dev/null 2>&1; then \
echo "⚠️ WARNING: java not found in PATH. Spring Boot tests will be skipped."; \
echo " Install Java 25 from: https://adoptium.net/ or your package manager"; \
fi
@echo "Installing goctl $(GOCTL_VERSION)..."
$(GOCMD) install github.com/zeromicro/go-zero/tools/goctl@$(GOCTL_VERSION)
@echo "Installing protoc-gen-connect-openapi $(PROTOC_GEN_CONNECT_OPENAPI_VERSION)..."
$(GOCMD) install github.com/sudorandom/protoc-gen-connect-openapi@$(PROTOC_GEN_CONNECT_OPENAPI_VERSION)
@echo "E2E dependencies installed"
# Run end-to-end tests (tests CLI via Cobra ExecuteContext)
# Use -p 1 to run packages sequentially to avoid port conflicts between Spring Boot apps.
# Without this flag, Go runs test packages in parallel by default, causing:
# - Port 8080 conflicts when multiple Spring Boot apps try to start simultaneously
# - JMX port 9001 conflicts for the spring-boot-maven-plugin stop goal
# - Random "Spring application lifecycle JMX bean not found" failures
test-e2e: e2e-deps
@echo "Running e2e tests..."
$(GOTEST) -v -p 1 -tags=e2e ./integration-tests/...
@echo "E2E tests complete"
# Run all tests (unit + e2e)
test-all: test test-e2e
@echo "All tests complete"
test-coverage: test
@echo "Generating coverage report..."
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
# Run golangci-lint (includes linters + formatters check)
lint:
@echo "Running linter..."
$(GOLINT) run ./...
@echo "Lint complete"
# Format code using golangci-lint formatters (gofumpt, goimports, gci)
fmt:
@echo "Formatting code..."
$(GOLINT) fmt ./...
$(GOCMD) fix ./...
@echo "Format complete"
install:
@echo "Installing..."
$(GOCMD) install $(MAIN_PACKAGE)
@echo "Install complete"
# Cross compilation
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY_UNIX) $(MAIN_PACKAGE)
# Development
dev: build
@echo "Running in development mode..."
./$(BUILD_DIR)/$(BINARY_NAME) --help
# Verify all checks pass (deps, fmt, lint, test)
# Mirrors CI workflow: checks for uncommitted changes after deps/fmt
verify: deps
@echo "Checking go.mod/go.sum are tidy..."
@git diff --exit-code -- go.mod go.sum
$(GOLINT) fmt ./...
$(GOCMD) fix ./...
@echo "Checking formatting produced no changes..."
@git diff --exit-code
$(GOLINT) run ./...
$(GOTEST) -race -v -coverprofile=coverage.out ./...
@echo "All checks passed!"
help:
@echo "Available targets:"
@echo " all - Clean, download dependencies, format, lint, test, and build"
@echo " build - Build the binary"
@echo " clean - Remove build artifacts"
@echo " deps - Download and tidy Go module dependencies"
@echo " e2e-deps - Install E2E test dependencies (goctl)"
@echo " test - Run unit tests with coverage"
@echo " test-e2e - Run E2E tests (auto-installs goctl)"
@echo " test-all - Run all tests (unit + e2e)"
@echo " test-coverage - Generate HTML coverage report"
@echo " lint - Run golangci-lint (linters + formatters check)"
@echo " fmt - Format code with golangci-lint formatters"
@echo " install - Install binary to GOPATH/bin"
@echo " build-linux - Build for Linux"
@echo " dev - Build and show help"
@echo " verify - Run all checks (deps tidy, fmt, lint, test) with change detection"
@echo " help - Show this help message"