This repository was archived by the owner on Jul 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (102 loc) · 4.2 KB
/
Copy pathMakefile
File metadata and controls
135 lines (102 loc) · 4.2 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
.PHONY: all build test lint vet fmt fmt-check deps clean coverage cloc help serve docker-mysql docker-build
REPO_PATH := github.com/cocoonstack/epoch
BINARY_NAME := epoch
GOIMPORTS_LOCAL_PREFIXES := github.com/cocoonstack/epoch
REVISION := $(shell git rev-parse HEAD || echo unknown)
BUILTAT := $(shell date +%Y-%m-%dT%H:%M:%S)
VERSION := $(shell git describe --tags $(shell git rev-list --tags --max-count=1) 2>/dev/null || echo dev)
GO_LDFLAGS ?= -X $(REPO_PATH)/version.Revision=$(REVISION) \
-X $(REPO_PATH)/version.BuiltAt=$(BUILTAT) \
-X $(REPO_PATH)/version.Version=$(VERSION)
ifneq ($(KEEP_SYMBOL), 1)
GO_LDFLAGS += -s
endif
BUILD_OUT ?= $(BINARY_NAME)
ifneq ($(GOOS),)
ifneq ($(GOARCH),)
BUILD_OUT := $(BINARY_NAME)-$(GOOS)-$(GOARCH)
endif
endif
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool versions
GOLANGCILINT_VERSION ?= v2.9.0
GOLANGCILINT_ROOT := $(LOCALBIN)/golangci-lint-$(GOLANGCILINT_VERSION)
GOLANGCILINT := $(GOLANGCILINT_ROOT)/golangci-lint
GOFMT := $(LOCALBIN)/gofumpt
GOIMPORTS := $(LOCALBIN)/goimports
## Target OSes for vet / lint
GOOSES ?= linux darwin
## Tool download targets
.PHONY: golangci-lint
golangci-lint: $(GOLANGCILINT)
$(GOLANGCILINT):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOLANGCILINT_ROOT) $(GOLANGCILINT_VERSION)
.PHONY: gofumpt
gofumpt: $(GOFMT)
$(GOFMT): | $(LOCALBIN)
GOBIN=$(LOCALBIN) go install mvdan.cc/gofumpt@latest
.PHONY: goimports
goimports: $(GOIMPORTS)
$(GOIMPORTS): | $(LOCALBIN)
GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@latest
# --- Primary targets ---
all: deps fmt lint test build ## Full pipeline: deps, fmt, lint, test, build
# --- Dependencies ---
deps: ## Tidy Go modules (no-op when running inside a Go workspace)
@if [ -z "$$(go env GOWORK)" ] || [ "$$(go env GOWORK)" = "off" ]; then \
go mod tidy; \
else \
echo "==> workspace mode active ($$(go env GOWORK)); skipping go mod tidy"; \
fi
# --- Build ---
build: ## Build epoch binary
CGO_ENABLED=0 go build -ldflags "$(GO_LDFLAGS)" -o $(BUILD_OUT) .
# --- Testing ---
test: vet ## Run tests with race detection and coverage
go test -race -timeout 120s -count=1 -cover -coverprofile=coverage.out ./...
coverage: test ## Generate and display coverage report
go tool cover -func=coverage.out
@echo ""
@echo "To view HTML coverage report: go tool cover -html=coverage.out"
# --- Code quality ---
vet: ## Run go vet on every target OS
@for goos in $(GOOSES); do \
echo "==> go vet GOOS=$$goos"; \
GOOS=$$goos go vet ./... || exit 1; \
done
lint: golangci-lint ## Run golangci-lint on every target OS
@for goos in $(GOOSES); do \
echo "==> golangci-lint GOOS=$$goos"; \
GOOS=$$goos $(GOLANGCILINT) run ./... || exit 1; \
done
fmt: gofumpt goimports ## Format code with gofumpt and goimports
$(GOFMT) -l -w .
$(GOIMPORTS) -l -w --local '$(GOIMPORTS_LOCAL_PREFIXES)' .
fmt-check: gofumpt goimports ## Check formatting (fails if files need formatting)
@test -z "$$($(GOFMT) -l .)" || { echo "Files need formatting (gofumpt):"; $(GOFMT) -l .; exit 1; }
@test -z "$$($(GOIMPORTS) -l --local '$(GOIMPORTS_LOCAL_PREFIXES)' .)" || { echo "Files need formatting (goimports):"; $(GOIMPORTS) -l --local '$(GOIMPORTS_LOCAL_PREFIXES)' .; exit 1; }
# --- Server ---
serve: ## Start local development server
go run . serve --dsn "epoch:epoch@tcp(127.0.0.1:3306)/epoch?parseTime=true"
docker-mysql: ## Start local MySQL via docker compose
docker compose up -d mysql
docker-build: ## Build Docker image
docker build -t epoch-server .
# --- Maintenance ---
clean: ## Remove build artifacts, coverage files, and test cache
rm -f $(BINARY_NAME) $(BINARY_NAME)-linux-* $(BINARY_NAME)-darwin-*
rm -rf bin/ dist/
rm -f coverage.out coverage.html coverage.txt
go clean -testcache
cloc: ## Count lines of code excluding tests (requires cloc)
cloc --exclude-dir=vendor,dist --exclude-ext=json --not-match-f='_test\.go$$' .
# --- Help ---
help: ## Show this help message
@echo "Epoch Makefile targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo ""