-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (53 loc) · 1.79 KB
/
Makefile
File metadata and controls
65 lines (53 loc) · 1.79 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
.PHONY: build test lint coverage clean all fmt vet golangci-lint
BINARY = bin/agent
GOFLAGS = -v
GOLANGCI_LINT ?= golangci-lint
# 默认目标 / Default target
all: lint test build
# 构建 / Build
build:
go build $(GOFLAGS) -o $(BINARY) ./cmd/agent
# 快速测试 / Quick test
test:
go test ./... -count=1
# 带竞态检测的测试 / Test with race detection
test-race:
go test -race ./... -count=1
# 覆盖率报告 / Coverage report
coverage:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.out
@echo ""
@echo "Coverage report: coverage.out"
@echo "View HTML: go tool cover -html=coverage.out"
# 格式化检查 / Format check
fmt:
@files=$$(gofmt -l .); \
if [ -n "$$files" ]; then \
echo "Files not gofmt-formatted:"; \
echo "$$files"; \
exit 1; \
fi
@echo "gofmt OK"
# 静态分析 / Static analysis
vet:
go vet ./...
# golangci-lint
golangci-lint:
@command -v $(GOLANGCI_LINT) >/dev/null 2>&1 || { \
echo "golangci-lint not found. Install the version in .golangci-lint-version first."; \
exit 1; \
}
$(GOLANGCI_LINT) run
# Lint (fmt + vet + golangci-lint)
lint: fmt vet golangci-lint
# 清理 / Clean
clean:
rm -rf bin/ coverage.out
# 跨平台构建(CGO_ENABLED=0 避免依赖目标机 glibc 版本,兼容旧 Linux)
# Cross-platform build (CGO_ENABLED=0 for glibc-independent binary on older Linux)
build-all:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o bin/coder-linux-amd64 ./cmd/agent
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o bin/coder-linux-arm64 ./cmd/agent
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o bin/coder-darwin-amd64 ./cmd/agent
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath -ldflags "-s -w" -o bin/coder-darwin-arm64 ./cmd/agent