-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
126 lines (100 loc) · 4.28 KB
/
Copy pathMakefile
File metadata and controls
126 lines (100 loc) · 4.28 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
.PHONY: all help build build-linux test vet fmt lint coverage coverage-html clean \
release integration ci ci-fast \
test-integration-quick test-integration-full
BINDIR := bin
COVERDIR := coverage
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -s -w -X main.version=$(VERSION)
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64
# Binaries built from ./cmd
CMD_BINS := daemon pilotctl
# Binaries included in release archives
RELEASE_BINS := daemon pilotctl
all: vet test build
help:
@echo "Pilot Protocol — Makefile targets"
@echo ""
@echo " build Build daemon + pilotctl into $(BINDIR)/"
@echo " build-linux Cross-compile for linux/amd64"
@echo " release Build cross-platform release archives"
@echo " test Run unit + in-repo tests"
@echo " vet go vet ./..."
@echo " fmt gofmt -s -w ."
@echo " lint golangci-lint run (if installed)"
@echo " coverage Run tests with coverage profile"
@echo " coverage-html Open coverage report in HTML"
@echo " integration Run local Docker-based integration suite"
@echo " clean Remove $(BINDIR)/ and $(COVERDIR)/"
# --- Build -------------------------------------------------------------------
define build_bin
go build $(if $(1),-ldflags "$(LDFLAGS)") -o $(BINDIR)/$(2)$(3) $(4)
endef
build:
@mkdir -p $(BINDIR)
$(foreach b,$(CMD_BINS),$(call build_bin,,$(b),,./cmd/$(b)))
build-linux:
@mkdir -p $(BINDIR)
$(foreach b,$(CMD_BINS),GOOS=linux GOARCH=amd64 $(call build_bin,,$(b),-linux,./cmd/$(b)))
# --- Tests / quality ---------------------------------------------------------
test:
go test -parallel 4 -count=1 ./pkg/... ./tests/
vet:
go vet ./...
fmt:
gofmt -s -w .
lint:
@command -v golangci-lint >/dev/null 2>&1 || { \
echo "golangci-lint not installed; see https://golangci-lint.run"; exit 1; }
golangci-lint run
coverage:
@mkdir -p $(COVERDIR)
@cd tests && go test -parallel 4 -count=1 \
-coverprofile=../$(COVERDIR)/coverage.out -covermode=atomic -timeout 5m
@go tool cover -func=$(COVERDIR)/coverage.out | tail -1 | awk '{print "Total coverage: " $$3}'
@go tool cover -func=$(COVERDIR)/coverage.out -o=$(COVERDIR)/coverage.txt
coverage-html: coverage
@go tool cover -html=$(COVERDIR)/coverage.out -o=$(COVERDIR)/coverage.html
@echo "Coverage report generated: $(COVERDIR)/coverage.html"
integration:
$(MAKE) -C tests/integration/local test
# --- Tiered test suites ------------------------------------------------------
# Tier 1 — CI fast (<2min). Pure Go unit + package tests. Runs on every push.
ci-fast: vet
go test ./pkg/... ./cmd/... ./internal/... -short -timeout 120s -parallel 4
# Tier 2 — integration quick (<10min). Docker-based tests that need a live
# cross-process environment AND finish fast. Skips long-running durability,
# resilience, and chaos tests. Runs pre-merge.
test-integration-quick:
cd tests/integration/local && \
if [ -f QUICK.txt ]; then \
bash ./run-all.sh -j 10 $$(grep -v '^#' QUICK.txt | tr '\n' ' '); \
else \
echo "QUICK.txt missing — run make test-integration-full"; exit 1; \
fi
# Tier 3 — integration full (~30min @ -j 10). Everything including 10min+
# durability, resilience, chaos. Nightly or on-demand.
test-integration-full:
cd tests/integration/local && bash ./run-all.sh -j 10
# --- Release -----------------------------------------------------------------
release:
@mkdir -p $(BINDIR)/release
@for platform in $(PLATFORMS); do \
os=$$(echo $$platform | cut -d/ -f1); \
arch=$$(echo $$platform | cut -d/ -f2); \
echo "Building $$os/$$arch..."; \
mkdir -p $(BINDIR)/release/$$os-$$arch; \
for bin in $(RELEASE_BINS); do \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -ldflags "$(LDFLAGS)" \
-o $(BINDIR)/release/$$os-$$arch/$$bin ./cmd/$$bin; \
done; \
tar -czf $(BINDIR)/release/pilot-$$os-$$arch.tar.gz \
-C $(BINDIR)/release/$$os-$$arch .; \
rm -rf $(BINDIR)/release/$$os-$$arch; \
done
@cd $(BINDIR)/release && shasum -a 256 *.tar.gz > checksums.txt
@echo "Release archives in $(BINDIR)/release/"
# --- Utility -----------------------------------------------------------------
ci: vet test build build-linux
@echo "CI: all checks passed"
clean:
rm -rf $(BINDIR) $(COVERDIR)