-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
179 lines (151 loc) · 7.07 KB
/
Makefile
File metadata and controls
179 lines (151 loc) · 7.07 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
PLUGIN_PATH := ./cmd/protoc-gen-gorums
dev_path := $(PLUGIN_PATH)/dev
gen_path := $(PLUGIN_PATH)/gengorums
gen_files := $(shell find $(gen_path) -name "*.go" -not -name "*_test.go")
zorums_proto := $(dev_path)/zorums.proto
static_file := $(gen_path)/template_static.go
static_files := $(shell find $(dev_path) -name "*.go" -not -name "zorums*" -not -name "*_test.go")
proto_path := $(dev_path):third_party:.
plugin_deps := gorums.pb.go $(static_file)
runtime_deps := internal/stream/stream.pb.go internal/stream/stream_grpc.pb.go
benchmark_deps := benchmark/benchmark.pb.go benchmark/benchmark_gorums.pb.go
.PHONY: all dev tools bootstrapgorums installgorums benchmark test compiletests genproto benchtest bench
all: dev benchmark compiletests
dev: installgorums $(runtime_deps)
@rm -f $(dev_path)/zorums*.pb.go
@protoc -I=$(proto_path) \
--go_out=:. \
--gorums_out=dev=true:. \
--go_opt=default_api_level=API_OPAQUE \
$(zorums_proto)
benchmark: installgorums $(benchmark_deps)
@go build -o cmd/benchmark/benchmark ./cmd/benchmark
$(static_file): $(static_files)
@cp $(static_file) $(static_file).bak
@protoc-gen-gorums --bundle=$(static_file)
%.pb.go : %.proto
@protoc -I=$(proto_path) \
--go_opt=default_api_level=API_OPAQUE \
--go_out=paths=source_relative:. $^
%_grpc.pb.go : %.proto
@protoc -I=$(proto_path) --go-grpc_out=paths=source_relative:. $^
%_gorums.pb.go : %.proto
@protoc -I=$(proto_path) --gorums_out=paths=source_relative:. $^
tools:
@go install tool
installgorums: bootstrapgorums $(gen_files) $(plugin_deps) Makefile
@go install $(PLUGIN_PATH)
ifeq (, $(shell which protoc-gen-gorums))
bootstrapgorums: tools
@echo "Bootstrapping gorums plugin"
@go install github.com/relab/gorums/cmd/protoc-gen-gorums
endif
compiletests: installgorums
@$(MAKE) --no-print-directory -C ./internal/tests all
test: compiletests benchtest
@go test ./...
integrationtest: compiletests
@go test -tags=integration ./...
testrace: compiletests
go test -race -cpu=1,2,4 ./...
# Run benchmarks with validation (short runs to verify they don't fail).
# Uses -benchtime=100x for limited iterations to avoid port exhaustion on macOS.
# Suppresses output on success; shows details on failure.
benchtest: compiletests
@if ! go test -run=^$$ -bench=. -benchtime=100x -count=1 ./... > /tmp/benchtest.out 2>&1; then \
echo "Benchmark validation failed:"; \
cat /tmp/benchtest.out; \
exit 1; \
fi
@echo "Benchmark validation passed"
# Run benchmarks with proper measurement (longer runs for performance analysis).
# Use -count=10 or more for statistically significant results.
# This only runs benchmarks in the main module and in internal/tests/oneway
# (when adding benchmarks elsewhere, update this target accordingly).
bench: compiletests
go test -run=^$$ -bench=. -benchtime=1s -count=10 . ./internal/tests/oneway
# Run stress tests that use longer durations for thorough testing.
# These tests are excluded from normal test runs via the 'stress' build tag.
stresstest: compiletests
go test -tags=stress ./...
# Warning: will probably run for 10 minutes; the timeout does not work
stressdev: tools
go test -c $(dev_path)
stress -timeout=5s -p=1 ./dev.test
# Warning: should not be aborted (CTRL-C), as otherwise it may
# leave behind compiled files in-place.
# Again the timeout does not work, so it will probably leave behind generated files.
stressgen: tools
cd ./internal/testprotos; go test -c
cd ./internal/testprotos; stress -timeout=10s -p=1 ./testprotos.test
rm ./internal/testprotos/testprotos.test
modernize:
@go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -fix ./...
# Regenerate all Gorums and protobuf generated files across the repo (dev, benchmark, internal/tests, examples).
# This will force regeneration even though the proto files have not changed.
genproto: installgorums dev
@echo "Regenerating all proto files (dev, benchmark, internal/tests, examples)"
@$(MAKE) -B -s dev
@$(MAKE) -B -s benchmark
@$(MAKE) -B -s --no-print-directory -C ./internal/tests all
@$(MAKE) -B -s --no-print-directory -C ./examples all
# Release helper targets to automate common release preparation steps.
# See doc/release-guide.md for details.
.PHONY: release-tools prepare-release release-pr release-publish
release-tools:
@echo "+ Checking for required release tools (gorelease, gh)..."
@command -v gorelease >/dev/null 2>&1 || go install golang.org/x/exp/cmd/gorelease@latest
@command -v gh >/dev/null || (echo "Please install 'gh' (GitHub CLI): brew install gh" && exit 1)
@echo "+ Checking installed tool versions"
@protoc --version || echo "protoc not found or not on PATH"
@protoc-gen-go --version || echo "protoc-gen-go not found or not on PATH"
@protoc-gen-go-grpc --version || echo "protoc-gen-go-grpc not found or not on PATH"
@protoc-gen-gorums --version || echo "protoc-gen-gorums not found or not on PATH"
@echo "+ OK"
prepare-release: release-tools
@echo "+ Upgrade module dependencies"
@go get -u ./... && go mod tidy
@cd examples && go get -u ./... && go mod tidy
@$(MAKE) genproto
@echo "+ Running gorelease to suggest the next version"
@tmp=$$(mktemp); \
gorelease > $$tmp; \
cat $$tmp | tee release-notes.txt; \
suggested=$$(awk -F': ' '/^Suggested version:/ {print $$2; exit}' $$tmp); \
echo "--------------------------------------------------------------------------"; \
echo ""; \
echo "gorelease suggests: $$suggested"; \
echo ""; \
echo "If the suggested version looks good, please edit the version constants in:"; \
echo " - internal/version/version.go"; \
echo " - version.go"; \
echo ""; \
echo "After editing those files, re-run to update generated files before creating the PR:"; \
echo " make genproto"; \
echo " go get -C examples github.com/relab/gorums@$${suggested:-vX.Y.Z}"; \
echo " go mod tidy && (cd examples && go mod tidy)"; \
echo ""; \
echo "Commit all changes and create an empty commit with the release notes:"; \
echo " git commit --allow-empty -F release-notes.txt"; \
echo ""; \
echo "Then create the release PR:"; \
echo " make release-pr VERSION=$${suggested:-vX.Y.Z}"
release-pr:
@if [ -z "$(VERSION)" ]; then echo "Usage: make release-pr VERSION=v0.9.0"; exit 1; fi
@if [ -n "$$(git status --porcelain --untracked-files=no)" ]; then echo "Uncommitted changes present; commit or stash first; aborting."; exit 1; fi
@BRANCH="release/$(VERSION)-devel"; \
git switch -c $$BRANCH; \
git add -A; \
git commit -m "Gorums release $(VERSION)"; \
git push -u origin HEAD; \
gh pr create --title "Gorums release $(VERSION)" --body "Release $(VERSION)"; \
echo "+ Release PR created. Opening in browser. Perform Squash and merge."; \
echo "+ After it is merged, run 'make release-publish VERSION=$(VERSION)' to publish the release."; \
sleep 2; \
gh pr view --web; \
release-publish:
@if [ -z "$(VERSION)" ]; then echo "Usage: make release-publish VERSION=v0.9.0"; exit 1; fi
@echo "+ Tagging and pushing tag: $(VERSION)"
@git tag -a $(VERSION) -m "Gorums $(VERSION)"
@git push origin $(VERSION)
@echo "+ Tag pushed. Use 'gh release create $(VERSION) --title \"Gorums $(VERSION)\"' to publish with release notes."