-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (108 loc) · 3.73 KB
/
Makefile
File metadata and controls
130 lines (108 loc) · 3.73 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
# Variables
BINARY_NAME=fli
MAIN_PATH=./cmd/fli
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -s -w"
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
BINARY_UNIX=$(BINARY_NAME)_unix
# Default target
.DEFAULT_GOAL := build
# Build the application
build:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) $(MAIN_PATH)
# Build for current platform
build-local:
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) $(MAIN_PATH)
# Build for multiple platforms
build-all: clean
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux-arm64 $(MAIN_PATH)
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
# Clean build artifacts
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_NAME)-*
rm -f coverage.out
# Run tests
test:
$(GOTEST) -v -race ./...
# Run tests with coverage
test-coverage:
$(GOTEST) -v -race -coverprofile=coverage.out -covermode=atomic ./...
go tool cover -html=coverage.out -o coverage.html
# Run tests with coverage and show in browser
test-coverage-html: test-coverage
open coverage.html
# Run benchmarks
bench:
$(GOTEST) -bench=. -benchmem ./...
# Run linting
lint:
golangci-lint run
# Install dependencies
deps:
$(GOMOD) download
$(GOMOD) tidy
# Update dependencies
deps-update:
$(GOMOD) get -u ./...
$(GOMOD) tidy
# Run security audit
audit:
govulncheck ./...
# Format code
fmt:
go fmt ./...
goimports -w .
# Generate documentation
docs:
godoc -http=:6060
# Install the binary (user-local installation)
install:
$(GOBUILD) $(LDFLAGS) -o $(HOME)/.local/bin/$(BINARY_NAME) $(MAIN_PATH)
@echo "Installed $(BINARY_NAME) to $(HOME)/.local/bin/"
@echo "Make sure $(HOME)/.local/bin/ is in your PATH"
# Install the binary (system-wide installation - requires sudo)
install-system:
$(GOBUILD) $(LDFLAGS) -o /usr/local/bin/$(BINARY_NAME) $(MAIN_PATH)
@echo "Installed $(BINARY_NAME) to /usr/local/bin/"
# Create release directory with binaries
release: build-all
mkdir -p release
mv $(BINARY_NAME)-* release/
cd release && sha256sum $(BINARY_NAME)-* > checksums.txt
# Test release process locally (dry run)
release-dry:
goreleaser release --snapshot --clean --skip-publish
# Help
help:
@echo "Available targets:"
@echo " build - Build the application"
@echo " build-local - Build for current platform"
@echo " build-all - Build for all platforms"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage"
@echo " bench - Run benchmarks"
@echo " lint - Run linting"
@echo " deps - Install dependencies"
@echo " deps-update - Update dependencies"
@echo " audit - Run security audit"
@echo " fmt - Format code"
@echo " docs - Generate documentation"
@echo " install - Install the binary (user-local)"
@echo " install-system - Install the binary (system-wide, requires sudo)"
@echo " release - Create release binaries"
@echo " release-dry - Test release process locally"
@echo " help - Show this help"
.PHONY: build build-local build-all clean test test-coverage test-coverage-html bench lint deps deps-update audit fmt docs install install-system release docker-build docker-run help