-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
200 lines (168 loc) · 5.83 KB
/
Makefile
File metadata and controls
200 lines (168 loc) · 5.83 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
# Makefile for makemigrations
# Build variables
BINARY_NAME=makemigrations
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_DATE=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)
GIT_COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
LDFLAGS=-ldflags="-s -w -X github.com/ocomsoft/makemigrations/internal/version.Version=$(VERSION) -X github.com/ocomsoft/makemigrations/internal/version.BuildDate=$(BUILD_DATE) -X github.com/ocomsoft/makemigrations/internal/version.GitCommit=$(GIT_COMMIT)"
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Platforms for cross-compilation
PLATFORMS=linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64
.PHONY: all build clean test deps fmt lint vet security release-build help publish-patch publish-minor publish-major
all: test build
# Build for current platform
build:
@echo "Building $(BINARY_NAME) v$(VERSION)..."
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) .
# Build for all platforms
release-build: clean
@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 $$output_name..."; \
CGO_ENABLED=0 GOOS=$$GOOS GOARCH=$$GOARCH $(GOBUILD) $(LDFLAGS) -o dist/$$output_name .; \
done
@echo "Generating checksums..."
@cd dist && sha256sum * > checksums.txt
@echo "Build complete! Binaries are in dist/"
# Clean build artifacts
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -rf dist/
# Run tests
test:
@echo "Running tests..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
# Run tests with coverage report
test-coverage: test
@echo "Generating coverage report..."
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Get dependencies
deps:
@echo "Getting dependencies..."
$(GOMOD) download
$(GOMOD) tidy
# Update dependencies
deps-update:
@echo "Updating dependencies..."
$(GOGET) -u ./...
$(GOMOD) tidy
# Format code
fmt:
@echo "Formatting code..."
$(GOCMD) fmt ./...
# Lint code
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not installed. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Vet code
vet:
@echo "Running go vet..."
$(GOCMD) vet ./...
# Security check
security:
@echo "Running security checks..."
@if command -v govulncheck >/dev/null 2>&1; then \
govulncheck ./...; \
else \
echo "govulncheck not installed. Install with: go install golang.org/x/vuln/cmd/govulncheck@latest"; \
fi
@if command -v gosec >/dev/null 2>&1; then \
gosec ./...; \
else \
echo "gosec not installed. Install with: go install github.com/securecodewarrior/gosec/v2/cmd/gosec@latest"; \
fi
# Install locally
install: build
@echo "Installing $(BINARY_NAME)..."
@mkdir -p $${GOPATH%/}/bin
cp $(BINARY_NAME) $${GOPATH%/}/bin/$(BINARY_NAME)
# Development workflow
dev: fmt vet lint test build
# CI workflow
ci: deps fmt vet lint test security build
# Run the application
run:
@echo "Running $(BINARY_NAME)..."
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) . && ./$(BINARY_NAME) $(ARGS)
# Show version info
version:
@echo "Version: $(VERSION)"
@echo "Build Date: $(BUILD_DATE)"
@echo "Git Commit: $(GIT_COMMIT)"
# Version bumping
bump-patch:
@echo "Bumping patch version..."
@./scripts/bump-version.sh patch
bump-minor:
@echo "Bumping minor version..."
@./scripts/bump-version.sh minor
bump-major:
@echo "Bumping major version..."
@./scripts/bump-version.sh major
bump-patch-dry:
@echo "Preview patch version bump..."
@./scripts/bump-version.sh patch --dry-run --allow-dirty
bump-minor-dry:
@echo "Preview minor version bump..."
@./scripts/bump-version.sh minor --dry-run --allow-dirty
bump-major-dry:
@echo "Preview major version bump..."
@./scripts/bump-version.sh major --dry-run --allow-dirty
# Publish targets: bump version then push main with tags
publish-patch: bump-patch
@echo "Pushing main with tags..."
git push origin main --tags
publish-minor: bump-minor
@echo "Pushing main with tags..."
git push origin main --tags
publish-major: bump-major
@echo "Pushing main with tags..."
git push origin main --tags
# Help
help:
@echo "Available targets:"
@echo " all - Run tests and build"
@echo " build - Build for current platform"
@echo " release-build - Build for all platforms"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " deps - Get dependencies"
@echo " deps-update - Update dependencies"
@echo " fmt - Format code"
@echo " lint - Run linter"
@echo " vet - Run go vet"
@echo " security - Run security checks"
@echo " install - Install locally"
@echo " dev - Development workflow (fmt, vet, lint, test, build)"
@echo " ci - CI workflow (deps, fmt, vet, lint, test, security, build)"
@echo " run - Build and run (use ARGS='--help' for arguments)"
@echo " version - Show version info"
@echo " bump-patch - Bump patch version"
@echo " bump-minor - Bump minor version"
@echo " bump-major - Bump major version"
@echo " bump-*-dry - Preview version bumps"
@echo " publish-patch - Bump patch version and push main with tags"
@echo " publish-minor - Bump minor version and push main with tags"
@echo " publish-major - Bump major version and push main with tags"
@echo " help - Show this help"
# Default target
.DEFAULT_GOAL := help