-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (100 loc) · 2.82 KB
/
Makefile
File metadata and controls
116 lines (100 loc) · 2.82 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
# Gitmit Makefile
# Variables
BINARY_NAME=gitmit
VERSION=$(shell git describe --tags --always --dirty)
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"
# Default target
.PHONY: all
all: clean test build
# Build the binary
.PHONY: build
build:
@echo "Building ${BINARY_NAME}..."
go build ${LDFLAGS} -o ${BINARY_NAME}
# Build for multiple platforms
.PHONY: build-all
build-all: clean
@echo "Building for multiple platforms..."
GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME}-linux-amd64
GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME}-darwin-amd64
GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o dist/${BINARY_NAME}-darwin-arm64
GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME}-windows-amd64.exe
# Run tests
.PHONY: test
test:
@echo "Running tests..."
go test -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
# Run linting
.PHONY: lint
lint:
@echo "Running linter..."
golangci-lint run
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
go fmt -s ./...
# Vet code
.PHONY: vet
vet:
@echo "Vetting code..."
go vet ./...
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning..."
rm -f ${BINARY_NAME}
rm -rf dist/
rm -f coverage.out coverage.html
# Install dependencies
.PHONY: deps
deps:
@echo "Installing dependencies..."
go mod download
go mod tidy
# Install the binary
.PHONY: install
install: build
@echo "Installing ${BINARY_NAME}..."
sudo mv ${BINARY_NAME} /usr/local/bin/
# Uninstall the binary
.PHONY: uninstall
uninstall:
@echo "Uninstalling ${BINARY_NAME}..."
sudo rm -f /usr/local/bin/${BINARY_NAME}
# Run the application
.PHONY: run
run: build
./${BINARY_NAME}
# Development setup
.PHONY: dev-setup
dev-setup:
@echo "Setting up development environment..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go mod download
# Help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Clean, test, and build"
@echo " build - Build the binary"
@echo " build-all - Build for multiple platforms"
@echo " test - Run tests"
@echo " test-coverage- Run tests with coverage report"
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " vet - Vet code"
@echo " clean - Clean build artifacts"
@echo " deps - Install dependencies"
@echo " install - Install binary to /usr/local/bin"
@echo " uninstall - Remove binary from /usr/local/bin"
@echo " run - Build and run the application"
@echo " dev-setup - Set up development environment"
@echo " help - Show this help message"