Skip to content

Commit 3d8a885

Browse files
committed
ci: add Makefile
1 parent b116e5b commit 3d8a885

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
SHELL := /bin/sh
2+
3+
PKG := ./...
4+
COVER_DIR := coverage
5+
COVER_PROFILE := $(COVER_DIR)/coverage.out
6+
COVER_HTML := $(COVER_DIR)/coverage.html
7+
8+
.PHONY: all test race vet fmt fmt-check lint lint-fix cover cover-html ci
9+
10+
all: test
11+
12+
# Run unit tests
13+
test:
14+
GOWORK=off go test $(PKG)
15+
16+
# Run tests with race detector
17+
race:
18+
GOWORK=off go test -race $(PKG)
19+
20+
# Static analysis
21+
vet:
22+
GOWORK=off go vet $(PKG)
23+
24+
format:
25+
@echo "🎨 Applying code formatters..."
26+
@echo " - Standard Go formatting..."
27+
@gofmt -w .
28+
@echo " - Organizing imports..."
29+
@goimports -w .
30+
@echo " - Strict formatting with gofumpt..."
31+
@gofumpt -w . 2>/dev/null || echo " (gofumpt not available, skipping)"
32+
@echo "✅ Code formatting complete"
33+
34+
# Check formatting without modifying files; fails if formatting needed
35+
fmt-check:
36+
@diff=$$(gofmt -s -l .); \
37+
if [ -n "$$diff" ]; then \
38+
echo "Files need formatting:"; echo "$$diff"; exit 1; \
39+
else \
40+
echo "Formatting OK"; \
41+
fi
42+
43+
# Lint: go vet + formatting check + optional golangci-lint if installed
44+
lint:
45+
@echo "Running go vet"; GOWORK=off go vet $(PKG)
46+
@echo "Checking formatting"; \
47+
diff=$$(gofmt -s -l .); if [ -n "$$diff" ]; then echo "Files need formatting:"; echo "$$diff"; exit 1; else echo "Formatting OK"; fi
48+
@if command -v golangci-lint >/dev/null 2>&1; then \
49+
echo "Running golangci-lint"; GOWORK=off golangci-lint run || true; \
50+
else \
51+
echo "golangci-lint not installed; skipping"; \
52+
fi
53+
54+
# Attempt to fix lint: gofmt + optional golangci-lint --fix if installed
55+
lint-fix: fmt
56+
@if command -v golangci-lint >/dev/null 2>&1; then \
57+
echo "Running golangci-lint --fix"; golangci-lint run --fix || true; \
58+
else \
59+
echo "golangci-lint not installed; skipping"; \
60+
fi
61+
62+
# Generate coverage profile and print total coverage
63+
cover:
64+
mkdir -p $(COVER_DIR)
65+
GOWORK=off go test -covermode=atomic -coverprofile=$(COVER_PROFILE) $(PKG)
66+
go tool cover -func=$(COVER_PROFILE) | tail -n 1
67+
68+
# Generate HTML coverage report
69+
cover-html: cover
70+
go tool cover -html=$(COVER_PROFILE) -o $(COVER_HTML)
71+
@echo "Wrote $(COVER_HTML)"
72+
73+
# CI-style aggregate target
74+
ci: fmt-check vet test cover

0 commit comments

Comments
 (0)