-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
155 lines (124 loc) · 5.62 KB
/
Makefile
File metadata and controls
155 lines (124 loc) · 5.62 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
.PHONY: all help build build-linux test vet fmt lint coverage coverage-html clean \
sdk-lib sdk-lib-linux sdk-lib-darwin release integration ci
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 (host build = no suffix, linux build = -linux suffix)
CMD_BINS := registry beacon daemon rendezvous pilotctl nameserver gateway updater
EXAMPLE_BINS := webserver client echo dataexchange eventstream secure
# Binaries included in release archives
RELEASE_BINS := daemon pilotctl gateway registry beacon rendezvous nameserver updater
all: vet test build
help:
@echo "Pilot Protocol — Makefile targets"
@echo ""
@echo " build Build all host binaries into $(BINDIR)/"
@echo " build-linux Cross-compile all binaries 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 " sdk-lib Build C-shared library for the native SDKs"
@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)))
$(foreach b,$(EXAMPLE_BINS),$(call build_bin,,$(b),,./examples/go/$(b)))
build-linux:
@mkdir -p $(BINDIR)
$(foreach b,$(CMD_BINS),GOOS=linux GOARCH=amd64 $(call build_bin,,$(b),-linux,./cmd/$(b)))
$(foreach b,$(EXAMPLE_BINS),GOOS=linux GOARCH=amd64 $(call build_bin,,$(b),-linux,./examples/go/$(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
@./scripts/generate-coverage-badge.sh
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.
# Catches regressions in logic that doesn't need a live docker stack.
ci-fast: vet
go test ./pkg/... ./cmd/... ./internal/... -short -timeout 120s -parallel 4
# Tier 2 — integration quick (<10min). The subset of docker-based tests
# that genuinely need a live cross-process environment AND finish fast.
# Skips long-running durability, resilience, and chaos tests. Runs pre-merge.
# Uses test_*.sh names as the whitelist in integration/local/QUICK.txt.
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 resilience. Nightly or on-demand.
test-integration-full:
cd tests/integration/local && bash ./run-all.sh -j 10
# --- SDK C-shared library ----------------------------------------------------
LIBNAME_DARWIN := libpilot.dylib
LIBNAME_LINUX := libpilot.so
LIBNAME_WIN := libpilot.dll
sdk-lib:
@mkdir -p $(BINDIR)
CGO_ENABLED=1 go build -buildmode=c-shared \
-o $(BINDIR)/$(LIBNAME_$(shell uname -s | sed 's/Darwin/DARWIN/;s/Linux/LINUX/')) \
./sdk/cgo/
@echo "Built shared library in $(BINDIR)/"
sdk-lib-linux:
@mkdir -p $(BINDIR)
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -buildmode=c-shared \
-o $(BINDIR)/$(LIBNAME_LINUX) ./sdk/cgo/
sdk-lib-darwin:
@mkdir -p $(BINDIR)
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -buildmode=c-shared \
-o $(BINDIR)/$(LIBNAME_DARWIN) ./sdk/cgo/
# --- 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)