-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
100 lines (85 loc) · 2.71 KB
/
Makefile
File metadata and controls
100 lines (85 loc) · 2.71 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
# DORA Metrics Server Makefile
# Version information
# For Go Releaser: use the current git tag, fallback to commit-dirty
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || git describe --tags --always --dirty 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
BUILD_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# Build flags
LDFLAGS := -X main.BuildVersion=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.BuildCommit=$(BUILD_COMMIT)
# Binary name and directory
BINARY := dora-metrics
BIN_DIR := bin
# Default target
.PHONY: all
all: build
# Build the application for current platform
.PHONY: build
build:
@echo "Building $(BINARY) for current platform..."
@echo "Version: $(VERSION)"
@echo "Build time: $(BUILD_TIME)"
@echo "Build commit: $(BUILD_COMMIT)"
@echo "Platform: $(shell go env GOOS)/$(shell go env GOARCH)"
@mkdir -p $(BIN_DIR)
go build -ldflags "$(LDFLAGS)" -o $(BIN_DIR)/$(BINARY) ./cmd/server
@echo "Build completed successfully!"
# Build for multiple platforms (macOS ARM, macOS Intel, Linux)
.PHONY: build-all
build-all:
@echo "Building for multiple platforms..."
@echo "Version: $(VERSION)"
@echo "Build time: $(BUILD_TIME)"
@echo "Build commit: $(BUILD_COMMIT)"
@mkdir -p dist
GOOS=darwin GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o dist/dora-metrics-macos-arm ./cmd/server
GOOS=darwin GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o dist/dora-metrics-macos-intel ./cmd/server
GOOS=linux GOARCH=arm64 go build -ldflags "$(LDFLAGS)" -o dist/dora-metrics-linux-arm ./cmd/server
GOOS=linux GOARCH=amd64 go build -ldflags "$(LDFLAGS)" -o dist/dora-metrics-linux-intel ./cmd/server
@echo "Multi-platform build completed successfully!"
@ls -la dist/
# Clean build artifacts
.PHONY: clean
clean:
rm -f $(BIN_DIR)/$(BINARY)
rm -rf dist/
# Run the application
.PHONY: run
run: build
./$(BIN_DIR)/$(BINARY)
# Run with help
.PHONY: help
help: build
./$(BIN_DIR)/$(BINARY) -help
# Run with version
.PHONY: version
version: build
./$(BIN_DIR)/$(BINARY) -version
# Install dependencies
.PHONY: deps
deps:
go mod tidy
go mod download
# Run tests
.PHONY: test
test:
go test ./...
# Run unit tests with coverage at project level
.PHONY: unit-test
unit-test:
@echo "Running unit tests with coverage..."
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
@echo ""
@echo "Coverage report saved to coverage.out"
@echo "To view HTML coverage report, run: go tool cover -html=coverage.out"
# Run linter
.PHONY: lint
lint:
golangci-lint run
# Show build information
.PHONY: info
info:
@echo "Version: $(VERSION)"
@echo "Build time: $(BUILD_TIME)"
@echo "Build commit: $(BUILD_COMMIT)"
@echo "Go version: $(shell go version)"