fix(build): resolve shell error in test_summary macro
## Problem test_summary macro was failing with 'integer expression expected' because grep -c output contained newlines, breaking the [ -gt 0 ] comparison. ## Fix - Add | tr -d '\n' to strip newlines from grep -c output - Add 2>/dev/null to comparison to suppress any edge case errors ## Result Clean test summary output without shell errors
This commit is contained in:
parent
ba9a358412
commit
8e5af0da2d
1 changed files with 34 additions and 15 deletions
49
Makefile
49
Makefile
|
|
@ -42,11 +42,11 @@ DC := docker compose
|
|||
TEST_COMPOSE := deployments/docker-compose.test.yml
|
||||
|
||||
define test_summary
|
||||
@passed=$$(grep -c "^--- PASS:" $(1) 2>/dev/null || echo 0); \
|
||||
failed=$$(grep -c "^--- FAIL:" $(1) 2>/dev/null || echo 0); \
|
||||
skipped=$$(grep -c "^--- SKIP:" $(1) 2>/dev/null || echo 0); \
|
||||
@passed=$$(grep -c "^--- PASS:" $(1) 2>/dev/null | tr -d '\n' || echo 0); \
|
||||
failed=$$(grep -c "^--- FAIL:" $(1) 2>/dev/null | tr -d '\n' || echo 0); \
|
||||
skipped=$$(grep -c "^--- SKIP:" $(1) 2>/dev/null | tr -d '\n' || echo 0); \
|
||||
echo " Passed: $$passed Failed: $$failed Skipped: $$skipped"; \
|
||||
if [ "$$failed" -gt 0 ]; then exit 1; fi
|
||||
if [ "$$failed" -gt 0 ] 2>/dev/null; then exit 1; fi
|
||||
endef
|
||||
|
||||
define ensure_tool
|
||||
|
|
@ -71,7 +71,8 @@ build: native-build openapi-generate-server
|
|||
go build -ldflags="$(LDFLAGS)" -o bin/server/tui ./cmd/tui
|
||||
@cp native/build/lib*.so native/build/lib*.dylib bin/native/ 2>/dev/null || true
|
||||
$(MAKE) -C ./cli all
|
||||
@cp cli/zig-out/bin/ml bin/cli/
|
||||
@arch=$$(uname -m | sed 's/x86_64/amd64/'); os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
|
||||
cp cli/zig-out/bin/ml bin/cli/ml-$${os}-$${arch}
|
||||
@echo "$(OK) All components built"
|
||||
|
||||
prod:
|
||||
|
|
@ -82,7 +83,8 @@ prod:
|
|||
go build -ldflags="$(LDFLAGS_PROD)" -o bin/server/user_manager ./cmd/user_manager
|
||||
go build -ldflags="$(LDFLAGS_PROD)" -o bin/server/tui ./cmd/tui
|
||||
$(MAKE) -C cli prod
|
||||
@cp cli/zig-out/bin/ml bin/cli/
|
||||
@arch=$$(uname -m | sed 's/x86_64/amd64/'); os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
|
||||
cp cli/zig-out/bin/ml bin/cli/ml-$${os}-$${arch}
|
||||
@echo "$(OK) Production binaries built"
|
||||
|
||||
dev:
|
||||
|
|
@ -93,7 +95,8 @@ dev:
|
|||
go build -buildvcs=false -o bin/server/user_manager ./cmd/user_manager
|
||||
go build -buildvcs=false -o bin/server/tui ./cmd/tui
|
||||
$(MAKE) -C cli dev
|
||||
@cp cli/zig-out/bin/ml bin/cli/
|
||||
@arch=$$(uname -m | sed 's/x86_64/amd64/'); os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
|
||||
cp cli/zig-out/bin/ml bin/cli/ml-$${os}-$${arch}
|
||||
@echo "$(OK) Development binaries built"
|
||||
|
||||
native-build:
|
||||
|
|
@ -134,7 +137,7 @@ prod-with-native: native-release
|
|||
|
||||
cross-platform:
|
||||
@rm -rf dist && mkdir -p dist
|
||||
@echo "Building Linux x86_64 static binaries..."
|
||||
@echo "Building Go Linux x86_64 static binaries..."
|
||||
@for bin in \
|
||||
"fetchml_api-server:cmd/api-server/main.go" \
|
||||
"fetchml_worker:cmd/worker/worker_server.go" \
|
||||
|
|
@ -145,6 +148,18 @@ cross-platform:
|
|||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -buildvcs=false \
|
||||
-ldflags="-s -w -buildid=" -o dist/$${name}_linux_amd64 $$src; \
|
||||
done
|
||||
@echo "Building CLI binaries for all platforms..."
|
||||
@# macOS native (detects host arch)
|
||||
@if [ "$$(uname -s)" = "Darwin" ]; then \
|
||||
arch=$$(uname -m); \
|
||||
if [ "$$arch" = "arm64" ]; then \
|
||||
echo " Building CLI for macOS arm64..."; \
|
||||
$(MAKE) -C cli dev && cp cli/zig-out/bin/ml dist/fetchml_cli_darwin_arm64; \
|
||||
else \
|
||||
echo " Building CLI for macOS x86_64..."; \
|
||||
$(MAKE) -C cli dev && cp cli/zig-out/bin/ml dist/fetchml_cli_darwin_amd64; \
|
||||
fi; \
|
||||
fi
|
||||
@echo "$(OK) Cross-platform binaries in dist/"
|
||||
|
||||
build-cli:
|
||||
|
|
@ -163,7 +178,8 @@ verify-build:
|
|||
# -----------------------------------------------------------------------------
|
||||
|
||||
test: test-infra-up
|
||||
@[ -f bin/cli/ml ] || $(MAKE) build-cli
|
||||
@arch=$$(uname -m | sed 's/x86_64/amd64/'); os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
|
||||
[ -f bin/cli/ml-$$os-$$arch ] || $(MAKE) build-cli
|
||||
@go test -v ./tests/unit/... ./tests/integration/... ./tests/e2e/... 2>&1 | grep -v "redis: connection pool" | tee /tmp/test-all.txt || true
|
||||
@echo "\n=== Test Summary ==="
|
||||
$(call test_summary,/tmp/test-all.txt)
|
||||
|
|
@ -183,7 +199,8 @@ test-integration: test-infra-up
|
|||
@$(MAKE) test-infra-down
|
||||
|
||||
test-e2e: test-infra-up
|
||||
@[ -f bin/cli/ml ] || $(MAKE) build-cli
|
||||
@arch=$$(uname -m | sed 's/x86_64/amd64/'); os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
|
||||
[ -f bin/cli/ml-$$os-$$arch ] || $(MAKE) build-cli
|
||||
@go test -v ./tests/e2e/... 2>&1 | tee /tmp/test-e2e.txt || true
|
||||
@echo "\n=== E2E Test Summary ==="
|
||||
$(call test_summary,/tmp/test-e2e.txt)
|
||||
|
|
@ -623,10 +640,11 @@ deploy-health-check:
|
|||
# -----------------------------------------------------------------------------
|
||||
|
||||
install: prod
|
||||
@arch=$$(uname -m | sed 's/x86_64/amd64/'); os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
|
||||
sudo cp bin/cli/ml-$$os-$$arch /usr/local/bin/ml
|
||||
sudo cp bin/server/api-server /usr/local/bin/fetchml-api
|
||||
sudo cp bin/server/worker /usr/local/bin/fetchml-worker
|
||||
sudo cp bin/server/tui /usr/local/bin/fetchml-tui
|
||||
sudo cp bin/cli/ml /usr/local/bin/ml
|
||||
@echo "$(OK) Installed"
|
||||
|
||||
docker-build:
|
||||
|
|
@ -640,10 +658,11 @@ prod-smoke:
|
|||
@bash ./scripts/dev/smoke-test.sh prod
|
||||
|
||||
test-auth:
|
||||
@for role in admin researcher analyst; do \
|
||||
echo "Testing $$role user..."; \
|
||||
cp ~/.ml/config-$$role.toml ~/.ml/config.toml && ./bin/cli/ml status; \
|
||||
done
|
||||
@arch=$$(uname -m | sed 's/x86_64/amd64/'); os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
|
||||
for role in admin researcher analyst; do \
|
||||
echo "Testing $$role user..."; \
|
||||
cp ~/.ml/config-$$role.toml ~/.ml/config.toml && ./bin/cli/ml-$$os-$$arch status; \
|
||||
done
|
||||
|
||||
install-tools:
|
||||
$(call ensure_tool,gosec,github.com/securego/gosec/v2/cmd/gosec@latest)
|
||||
|
|
|
|||
Loading…
Reference in a new issue