Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (95 loc) · 3.87 KB
/
Copy pathMakefile
File metadata and controls
124 lines (95 loc) · 3.87 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
##########################
### SAGE Gateway Makefile #
##########################
BINARY := sagegw
BIN_DIR := bin
CMD := ./cmd/sagegw
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -ldflags "-X main.Version=$(VERSION) -X main.Commit=$(COMMIT) -X main.BuildDate=$(BUILD_DATE)"
CONFIG_PATH ?=
DOCKER_IMAGE ?= sage:latest
.DEFAULT_GOAL := help
.PHONY: help
help: ## List all available targets with descriptions
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
##########################
### Build ###
##########################
.PHONY: sage_build
sage_build: ## Build the sagegw binary to bin/sagegw
mkdir -p $(BIN_DIR)
CGO_ENABLED=0 go build $(LDFLAGS) -o $(BIN_DIR)/$(BINARY) $(CMD)
.PHONY: sage_run
sage_run: ## Run sagegw directly (set CONFIG_PATH env variable)
go run $(LDFLAGS) $(CMD) -config $(CONFIG_PATH)
##########################
### Test ###
##########################
.PHONY: test_unit
test_unit: ## Run unit tests (short, with race detector)
go test ./... -short -count=1 -race
.PHONY: test_all
test_all: ## Run all tests (no -short, with race detector)
go test ./... -count=1 -race
.PHONY: test_cover
test_cover: ## Run tests and open HTML coverage report
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
##########################
### Lint ###
##########################
.PHONY: go_lint
go_lint: ## Run golangci-lint, then fail on any unreachable function
golangci-lint run --timeout 5m
$(MAKE) deadcode
# deadcode is what catches "built but never wired" at the function level: a
# constructor nothing calls, an option nothing passes. The 2026-09-04 audit
# found five of those, all of which had been sitting in the tree for weeks.
# -test counts test callers as reachable, since a test-only helper is a
# choice; lines from test files themselves are compile-time interface stubs
# and are filtered out.
DEADCODE_VERSION ?= v0.49.0
.PHONY: deadcode
deadcode: ## Fail on unreachable functions (excluding test files)
@out=$$(go run golang.org/x/tools/cmd/deadcode@$(DEADCODE_VERSION) -test ./... | grep -v '_test\.go:' || true); \
if [ -n "$$out" ]; then echo "$$out"; echo "deadcode: unreachable functions above; wire them or delete them"; exit 1; fi
##########################
### Docs ###
##########################
.PHONY: docs
docs: ## Regenerate the reference docs under docs/ from source
go run ./cmd/docgen -root .
##########################
### Docker ###
##########################
.PHONY: docker_build
docker_build: ## Build the Docker image (sage:latest)
docker build -t $(DOCKER_IMAGE) .
.PHONY: docker_run
docker_run: ## Run the Docker image (requires CONFIG_PATH)
docker run --rm \
-v $(abspath $(CONFIG_PATH)):/etc/sage/config.yaml:ro \
-p 3069:3069 \
$(DOCKER_IMAGE) -config /etc/sage/config.yaml
##########################
### E2E Tests ###
##########################
SAGE_URL ?= http://localhost:3069
.PHONY: e2e_test
e2e_test: ## Run E2E tests against SAGE_URL (default: http://localhost:3069)
go test ./e2e/... -tags e2e -count=1 -timeout 120s -v
.PHONY: load_test
load_test: ## Run load tests against a running SAGE instance
SAGE_URL=$(SAGE_URL) go test ./e2e/... -tags e2e -run TestLoad -count=1 -timeout 120s -v
.PHONY: integration_test
integration_test: ## Run integration tests (requires fullnode + SAGE_CONFIG)
go test ./protocol/shannon/... -tags integration -count=1 -timeout 60s -v
##########################
### Clean ###
##########################
.PHONY: clean
clean: ## Remove build artifacts and coverage reports
rm -rf $(BIN_DIR)/ coverage.out