-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
97 lines (82 loc) · 2.5 KB
/
Makefile
File metadata and controls
97 lines (82 loc) · 2.5 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
.PHONY: all build test clean docker-build docker-push install
# Variables
BINARY_NAME=refill
VERSION?=dev
BUILD_TIME=$(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS=-ldflags "-w -s -X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)"
# Default target
all: test build
# Build the binary
build:
@echo "Building $(BINARY_NAME)..."
go build $(LDFLAGS) -o $(BINARY_NAME) ./cmd/refill
# Build for multiple platforms
build-all:
@echo "Building for multiple platforms..."
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BINARY_NAME)-linux-amd64 ./cmd/refill
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BINARY_NAME)-linux-arm64 ./cmd/refill
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BINARY_NAME)-darwin-amd64 ./cmd/refill
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BINARY_NAME)-darwin-arm64 ./cmd/refill
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BINARY_NAME)-windows-amd64.exe ./cmd/refill
# Run tests
test:
@echo "Running tests..."
go test -v -race -coverprofile=coverage.out ./...
# Run tests with coverage report
coverage: test
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Clean build artifacts
clean:
@echo "Cleaning..."
rm -f $(BINARY_NAME)
rm -f $(BINARY_NAME)-*
rm -f coverage.out coverage.html
rm -rf out/
# Install the binary
install: build
@echo "Installing $(BINARY_NAME)..."
cp $(BINARY_NAME) /usr/local/bin/
# Build Docker image
docker-build:
@echo "Building Docker image..."
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
-t refill:$(VERSION) \
-t refill:latest \
.
# Push Docker image
docker-push:
@echo "Pushing Docker image..."
docker push refill:$(VERSION)
docker push refill:latest
# Run locally
run:
go run ./cmd/refill run
# Format code
fmt:
go fmt ./...
# Lint code
lint:
golangci-lint run
# Download dependencies
deps:
go mod download
go mod tidy
# Show help
help:
@echo "Available targets:"
@echo " all - Run tests and build"
@echo " build - Build the binary"
@echo " build-all - Build for multiple platforms"
@echo " test - Run tests"
@echo " coverage - Generate coverage report"
@echo " clean - Clean build artifacts"
@echo " install - Install the binary"
@echo " docker-build - Build Docker image"
@echo " docker-push - Push Docker image"
@echo " run - Run locally"
@echo " fmt - Format code"
@echo " lint - Lint code"
@echo " deps - Download dependencies"