-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
224 lines (194 loc) · 5.34 KB
/
Makefile
File metadata and controls
224 lines (194 loc) · 5.34 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
# Makefile for Brev Cloud SDK
# A vendor-agnostic Go SDK for managing clusterable, GPU-accelerated compute
# Variables
BINARY_NAME=compute
MODULE_NAME=github.com/brevdev/cloud
BUILD_DIR=build
COVERAGE_DIR=coverage
# Load environment variables from .env file if it exists
ifneq (,$(wildcard .env))
include .env
export
endif
# Go related variables
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOLINT=golangci-lint
GOVET=$(GOCMD) vet
GOFMT=gofumpt
GOINSTALL=$(GOCMD) install
GOSEC=gosec
# Third party tools
ARTIFACT_GOLINT=github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0
ARTIFACT_GOSEC=github.com/securego/gosec/v2/cmd/gosec@v2.22.8
ARTIFACT_GOFUMPT=mvdan.cc/gofumpt@v0.9.2
# Build flags
LDFLAGS=-ldflags "-X main.Version=$(shell git describe --tags --always --dirty) -X main.BuildTime=$(shell date -u '+%Y-%m-%d_%H:%M:%S')"
# Default target
.PHONY: all
all: clean build test lint
# Build the project
.PHONY: build
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) ./...
# Build for multiple platforms
.PHONY: build-all
build-all: build-linux build-darwin build-windows
.PHONY: build-linux
build-linux:
@echo "Building for Linux..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 $(GOBUILD) ./...
.PHONY: build-darwin
build-darwin:
@echo "Building for macOS..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 $(GOBUILD) ./...
.PHONY: build-windows
build-windows:
@echo "Building for Windows..."
@mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 $(GOBUILD) ./...
# Run tests
.PHONY: test
test:
@echo "Running tests..."
$(GOTEST) -v -short ./...
# Run validation tests
.PHONY: test-validation
test-validation:
@echo "Running validation tests..."
$(GOTEST) -v -short=false ./...
# Run all tests including validation
.PHONY: test-all
test-all:
@echo "Running all tests..."
$(GOTEST) -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
@mkdir -p $(COVERAGE_DIR)
$(GOTEST) -v -coverprofile=$(COVERAGE_DIR)/coverage.out ./...
$(GOCMD) tool cover -html=$(COVERAGE_DIR)/coverage.out -o $(COVERAGE_DIR)/coverage.html
@echo "Coverage report generated at $(COVERAGE_DIR)/coverage.html"
# Run tests with race detection
.PHONY: test-race
test-race:
@echo "Running tests with race detection..."
$(GOTEST) -race -v ./...
# Run benchmarks
.PHONY: bench
bench:
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
# Lint the code
.PHONY: lint
lint:
@echo "Running linter..."
@if ! command -v $(GOLINT) > /dev/null 2>&1; then \
$(GOINSTALL) $(ARTIFACT_GOLINT); \
fi
$(GOLINT) run ./...
# Run go vet
.PHONY: vet
vet:
@echo "Running go vet..."
$(GOVET) ./...
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
$(GOFMT) -w .
# Check if code is formatted
.PHONY: fmt-check
fmt-check:
@echo "Checking code formatting..."
@files=$$($(GOFMT) -l .); \
if [ -n "$$files" ]; then \
echo "Code is not formatted. Run 'make fmt' to format."; \
$(GOFMT) -l .; \
echo "$$files"; \
exit 1; \
else \
echo "Code is properly formatted."; \
fi
# Security scan
.PHONY: security
security:
@echo "Running security scan..."
@if ! command -v $(GOSEC) > /dev/null 2>&1; then \
echo "gosec not found. Installing..."; \
$(GOINSTALL) $(ARTIFACT_GOSEC); \
fi
$(GOSEC) ./...
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
rm -rf $(COVERAGE_DIR)
# Install dependencies
.PHONY: deps
deps:
@echo "Installing dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Update dependencies
.PHONY: deps-update
deps-update:
@echo "Updating dependencies..."
$(GOCMD) get -u ./...
$(GOMOD) tidy
# Verify dependencies
.PHONY: deps-verify
deps-verify:
@echo "Verifying dependencies..."
$(GOMOD) verify
# Generate documentation
.PHONY: docs
docs:
@echo "Generating documentation..."
$(GOCMD) doc -all ./...
# Run all checks (lint, vet, fmt-check, test)
.PHONY: check
check: lint vet fmt-check test
# Install tools
.PHONY: install-tools
install-tools:
@echo "Installing development tools..."
$(GOINSTALL) $(ARTIFACT_GOLINT)
$(GOINSTALL) $(ARTIFACT_GOSEC)
$(GOINSTALL) $(ARTIFACT_GOFUMPT)
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " build - Build the project"
@echo " build-all - Build for Linux, macOS, and Windows"
@echo " test - Run tests (with -short flag)"
@echo " test-validation - Run validation tests (without -short flag)"
@echo " test-all - Run all tests including validation"
@echo " test-coverage - Run tests with coverage report"
@echo " test-race - Run tests with race detection"
@echo " bench - Run benchmarks"
@echo " lint - Run linter (golangci-lint)"
@echo " vet - Run go vet"
@echo " fmt - Format code"
@echo " fmt-check - Check if code is formatted"
@echo " security - Run security scan (gosec)"
@echo " clean - Clean build artifacts"
@echo " deps - Install dependencies"
@echo " deps-update - Update dependencies"
@echo " deps-verify - Verify dependencies"
@echo " docs - Generate documentation"
@echo " check - Run all checks (lint, vet, fmt-check, test)"
@echo " install-tools - Install development tools"
@echo " help - Show this help message"