forked from inputlayer/inputlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
302 lines (267 loc) · 10.4 KB
/
Makefile
File metadata and controls
302 lines (267 loc) · 10.4 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
.PHONY: all ci fmt fmt-check lint test test-fast test-release unit-test integration-test e2e-test e2e-update test-affected doc doc-check check build build-release clean fix release snapshot-test test-all ci-test-all flush-dev docker docker-run
SHELL := /bin/bash
# Default target
all: ci
# Developer Workflow
# Fast feedback loop - unit + integration tests only (~30s)
test-fast: check unit-test
@echo "Fast tests complete."
# Pre-commit gate - unit + integration + snapshot E2E (~60-90s)
test: check unit-test e2e-test
@echo "All tests complete."
# Full verification (CI, pre-merge)
# Runs everything: lint, build, unit+integration tests, snapshot E2E tests
# All tests run in parallel. Zero ignored tests allowed. Cleanup verified.
test-all: check
@FAILURES=0; \
STRIP_ANSI='s/\x1b\[[0-9;]*m//g'; \
NCPU=$$(sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4); \
echo "Running all tests ($$NCPU CPUs)..."; \
echo ""; \
echo "=== Cleanup (pre-test) ==="; \
rm -rf ./data 2>/dev/null || true; \
echo "Cleaned ./data directory"; \
echo ""; \
echo "=== Build (release) ==="; \
if cargo build --all-features --release 2>&1; then \
BUILD_STATUS="PASS"; \
else \
BUILD_STATUS="FAIL"; \
FAILURES=$$((FAILURES + 1)); \
fi; \
echo ""; \
echo "=== Unit + Integration Tests ($$NCPU threads) ==="; \
UNIT_TMPFILE=$$(mktemp); \
set -o pipefail; \
RUST_TEST_THREADS=$$NCPU cargo test --all-features -- --test-threads=$$NCPU --format=pretty \
2>&1 | tee "$$UNIT_TMPFILE"; \
UNIT_EXIT=$${PIPESTATUS[0]}; \
tail -5 "$$UNIT_TMPFILE"; \
UNIT_PASSED=$$(grep -E "^test result:" "$$UNIT_TMPFILE" | awk '{sum += $$4} END {print sum+0}'); \
UNIT_FAILED=$$(grep -E "^test result:" "$$UNIT_TMPFILE" | awk '{sum += $$6} END {print sum+0}'); \
UNIT_IGNORED=$$(grep -E "^test result:" "$$UNIT_TMPFILE" | awk '{sum += $$8} END {print sum+0}'); \
rm -f "$$UNIT_TMPFILE"; \
if [ $$UNIT_EXIT -ne 0 ]; then FAILURES=$$((FAILURES + 1)); fi; \
if [ "$$UNIT_IGNORED" -gt 0 ] 2>/dev/null; then \
echo "ERROR: $$UNIT_IGNORED ignored test(s) detected. No tests may be ignored."; \
FAILURES=$$((FAILURES + 1)); \
fi; \
echo ""; \
echo "Settling before snapshot tests..."; \
lsof -ti :8080 | xargs kill -9 2>/dev/null || true; \
rm -rf ./data 2>/dev/null || true; \
echo "Cleaning debug artifacts to free memory..."; \
rm -rf target/debug 2>/dev/null || true; \
sync 2>/dev/null || true; \
sleep 8; \
echo ""; \
echo "=== Snapshot Tests (E2E) ==="; \
SNAP_TMPFILE=$$(mktemp); \
set -o pipefail; \
./scripts/run_snapshot_tests.sh --skip-build 2>&1 | tee "$$SNAP_TMPFILE"; \
SNAP_EXIT=$${PIPESTATUS[0]}; \
tail -10 "$$SNAP_TMPFILE"; \
SNAP_PASSED=$$(sed "$$STRIP_ANSI" "$$SNAP_TMPFILE" | grep -E "^Passed:" | awk '{print $$2}'); \
SNAP_FAILED=$$(sed "$$STRIP_ANSI" "$$SNAP_TMPFILE" | grep -E "^Failed:" | awk '{print $$2}'); \
rm -f "$$SNAP_TMPFILE"; \
if [ $$SNAP_EXIT -ne 0 ]; then FAILURES=$$((FAILURES + 1)); fi; \
echo ""; \
echo "=== Cleanup Verification ==="; \
STALE_DATA=""; \
if [ -d "./data" ]; then \
STALE_KGS=$$(ls -d ./data/*/ 2>/dev/null | grep -v persist | grep -v metadata | grep -v '/default/' | wc -l | tr -d ' '); \
if [ "$$STALE_KGS" -gt 0 ]; then \
STALE_DATA="$$STALE_KGS stale KG directories in ./data"; \
fi; \
fi; \
if [ -n "$$STALE_DATA" ]; then \
echo "WARNING: $$STALE_DATA"; \
else \
echo "Clean: no stale test data"; \
fi; \
rm -rf ./data 2>/dev/null || true; \
echo ""; \
TOTAL=$$(($$UNIT_PASSED + $${SNAP_PASSED:-0})); \
TOTAL_FAILED=$$(($$UNIT_FAILED + $${SNAP_FAILED:-0})); \
echo "==========================================="; \
echo " TEST SUMMARY"; \
echo "==========================================="; \
echo ""; \
printf " | %-14s | %-48s |\n" "Category" "Status"; \
printf " |----------------|--------------------------------------------------|\n"; \
printf " | %-14s | %-48s |\n" "Build" "$$BUILD_STATUS"; \
printf " | %-14s | %-48s |\n" "Cargo Tests" "$$UNIT_PASSED passed, $$UNIT_FAILED failed, $$UNIT_IGNORED ignored"; \
printf " | %-14s | %-48s |\n" "Snapshot Tests" "$${SNAP_PASSED:-0} passed, $${SNAP_FAILED:-0} failed"; \
printf " | %-14s | %-48s |\n" "TOTAL" "$$TOTAL passed, $$TOTAL_FAILED failed"; \
echo ""; \
echo "==========================================="; \
if [ $$FAILURES -ne 0 ]; then \
echo "SOME CHECKS FAILED ($$FAILURES)"; \
exit 1; \
fi; \
echo "ALL CHECKS PASSED"
# CI-friendly full verification (disk/memory-constrained free-tier runners)
# Same checks as test-all but with:
# - Thin LTO instead of full LTO (halves linker peak memory)
# - More codegen units (reduces per-unit memory)
# - Capped test parallelism (DD workers are memory-hungry)
# - Capped snapshot parallelism
# - Debug artifacts cleaned between unit and snapshot tests (saves ~11GB disk)
ci-test-all:
@FAILURES=0; \
STRIP_ANSI='s/\x1b\[[0-9;]*m//g'; \
CI_JOBS=$$(nproc 2>/dev/null || echo 4); \
echo "Running all tests (CI mode, $${CI_JOBS} parallel)..."; \
echo ""; \
echo "=== Build (release, thin LTO) ==="; \
if CARGO_PROFILE_RELEASE_LTO=thin CARGO_PROFILE_RELEASE_CODEGEN_UNITS=4 \
cargo build --all-features --release 2>&1; then \
BUILD_STATUS="PASS"; \
else \
BUILD_STATUS="FAIL"; \
FAILURES=$$((FAILURES + 1)); \
fi; \
echo ""; \
echo "=== Unit Tests ==="; \
UNIT_TMPFILE=$$(mktemp); \
set -o pipefail; \
RUST_TEST_THREADS=$$CI_JOBS cargo test --all-features -- --test-threads=$$CI_JOBS --format=pretty \
2>&1 | tee "$$UNIT_TMPFILE"; \
UNIT_EXIT=$${PIPESTATUS[0]}; \
tail -5 "$$UNIT_TMPFILE"; \
UNIT_PASSED=$$(grep -E "^test result:" "$$UNIT_TMPFILE" | awk '{sum += $$4} END {print sum+0}'); \
UNIT_FAILED=$$(grep -E "^test result:" "$$UNIT_TMPFILE" | awk '{sum += $$6} END {print sum+0}'); \
rm -f "$$UNIT_TMPFILE"; \
if [ $$UNIT_EXIT -ne 0 ]; then FAILURES=$$((FAILURES + 1)); fi; \
echo ""; \
echo "Cleaning debug artifacts to free disk space..."; \
rm -rf target/debug 2>/dev/null || true; \
echo ""; \
echo "=== Snapshot Tests (E2E, $$CI_JOBS parallel) ==="; \
SNAP_TMPFILE=$$(mktemp); \
set -o pipefail; \
CARGO_PROFILE_RELEASE_LTO=thin CARGO_PROFILE_RELEASE_CODEGEN_UNITS=4 \
./scripts/run_snapshot_tests.sh --skip-build -j $$CI_JOBS 2>&1 | tee "$$SNAP_TMPFILE"; \
SNAP_EXIT=$${PIPESTATUS[0]}; \
tail -10 "$$SNAP_TMPFILE"; \
SNAP_PASSED=$$(sed "$$STRIP_ANSI" "$$SNAP_TMPFILE" | grep -E "^Passed:" | awk '{print $$2}'); \
SNAP_FAILED=$$(sed "$$STRIP_ANSI" "$$SNAP_TMPFILE" | grep -E "^Failed:" | awk '{print $$2}'); \
rm -f "$$SNAP_TMPFILE"; \
if [ $$SNAP_EXIT -ne 0 ]; then FAILURES=$$((FAILURES + 1)); fi; \
echo ""; \
echo "==========================================="; \
echo " CI TEST SUMMARY"; \
echo "==========================================="; \
echo ""; \
printf " | %-14s | %-48s |\n" "Category" "Status"; \
printf " |----------------|--------------------------------------------------|\n"; \
printf " | %-14s | %-48s |\n" "Build" "$$BUILD_STATUS"; \
printf " | %-14s | %-48s |\n" "Unit Tests" "$$UNIT_PASSED passed, $$UNIT_FAILED failed"; \
printf " | %-14s | %-48s |\n" "Snapshot Tests" "$${SNAP_PASSED:-0} passed, $${SNAP_FAILED:-0} failed"; \
echo ""; \
echo "==========================================="; \
if [ $$FAILURES -ne 0 ]; then \
echo "SOME CHECKS FAILED ($$FAILURES)"; \
exit 1; \
fi; \
echo "ALL CHECKS PASSED"
# CI target - runs all checks that CI performs
ci: check ci-test-all
@echo "All CI checks passed!"
# Individual Test Tiers
# Tier 1: Unit tests (cargo test - includes all #[test] functions)
unit-test:
cargo test --all-features
# Tier 2: Integration tests only
integration-test:
cargo test --all-features --test '*'
# Tier 3: E2E snapshot tests (parallel, against live server)
e2e-test:
./scripts/run_snapshot_tests.sh
# Regenerate snapshot .idl.out files (sequential mode)
e2e-update:
./scripts/run_snapshot_tests.sh --update
# Run only tests affected by uncommitted changes
test-affected:
./scripts/test-affected.sh
# Legacy alias for e2e-test
snapshot-test: e2e-test
# Code Quality
# Format code
fmt:
cargo fmt --all
# Check formatting (CI mode - fails if not formatted)
fmt-check:
cargo fmt --all -- --check
# Run clippy lints
lint:
cargo clippy --all-features -- -D warnings
# Check compilation + formatting + lints + docs (quality gate)
check: fmt-check lint doc-check
cargo check --all-features
# Fix formatting and lint issues automatically where possible
fix: fmt
cargo clippy --all-features --fix --allow-dirty --allow-staged -- -D warnings
# Build
# Build the project
build:
cargo build --all-features
# Build in release mode
build-release:
cargo build --all-features --release
# Run unit tests in release mode
test-release:
cargo test --all-features --release
# Clean build artifacts
clean:
cargo clean
# Documentation
# Build documentation
doc:
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
# Check documentation (CI mode)
doc-check:
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
# Release & Maintenance
# Create a release branch with updated version
# Usage: make release VERSION=x.x.x
release:
ifndef VERSION
$(error VERSION is not set. Usage: make release VERSION=x.x.x)
endif
@echo "Creating release branch for version $(VERSION)..."
@# Ensure we're on a clean working tree
@if [ -n "$$(git status --porcelain)" ]; then \
echo "Error: Working tree is not clean. Please commit or stash changes."; \
exit 1; \
fi
@# Create and checkout release branch
git checkout -b release/$(VERSION)
@# Update version in Cargo.toml
@sed -i.bak 's/^version = ".*"/version = "$(VERSION)"/' Cargo.toml && rm -f Cargo.toml.bak
@# Update Cargo.lock
cargo update --workspace
@# Run CI checks to ensure everything is valid
@$(MAKE) ci
@# Commit changes
git add Cargo.toml Cargo.lock
git commit -m "chore: bump version to $(VERSION)"
@# Push branch to origin
git push -u origin release/$(VERSION)
@echo ""
@echo "Release branch 'release/$(VERSION)' created and pushed!"
@echo "Next steps:"
@echo " 1. Create a PR from release/$(VERSION) to main"
@echo " 2. After merge, create and push tag: git tag v$(VERSION) && git push origin v$(VERSION)"
# Docker
# Build Docker image
docker:
DOCKER_BUILDKIT=1 docker build -t inputlayer .
# Run Docker container
docker-run: docker
docker run --rm -p 8080:8080 -v inputlayer-data:/var/lib/inputlayer/data inputlayer
# Flush development data - removes data folder to reset to empty state
flush-dev:
@echo "Flushing development data..."
@rm -rf ./data
@echo "Data folder removed. Server will recreate default knowledge graph on next start."