#!/usr/bin/env bash # # Build (and optionally test) all module solutions under src/. # # Usage: # ./scripts/build-all-solutions.sh # build only # ./scripts/build-all-solutions.sh --test # build + test # ./scripts/build-all-solutions.sh --test --configuration Release set -euo pipefail REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" SRC_DIR="$REPO_ROOT/src" RUN_TESTS=false CONFIGURATION="Debug" STOP_REPO_HOST_PROCESSES=false while [[ $# -gt 0 ]]; do case "$1" in --test|-t) RUN_TESTS=true; shift ;; --stop-repo-host-processes) STOP_REPO_HOST_PROCESSES=true; shift ;; --configuration|-c) CONFIGURATION="$2"; shift 2 ;; *) echo "Unknown option: $1" >&2; exit 1 ;; esac done stop_repo_host_processes() { local found=0 while IFS= read -r line; do [[ -z "$line" ]] && continue local pid="${line%% *}" local cmd="${line#* }" [[ "$cmd" != *"$REPO_ROOT"* ]] && continue [[ "$cmd" != *"StellaOps."* ]] && continue [[ "$pid" == "$$" ]] && continue if (( found == 0 )); then echo "Stopping repo-local Stella host processes before build." fi echo " - [$pid] $cmd" kill "$pid" 2>/dev/null || true sleep 1 if kill -0 "$pid" 2>/dev/null; then kill -9 "$pid" 2>/dev/null || true fi found=1 done < <(ps -eo pid=,args=) if (( found == 0 )); then echo "No repo-local Stella host processes detected." else echo "Repo-local Stella host processes stopped." fi } if $STOP_REPO_HOST_PROCESSES; then stop_repo_host_processes fi # Discover repo-owned solutions only; skip generated output trees. mapfile -t SOLUTIONS < <( find "$SRC_DIR" \ \( -path '*/node_modules/*' -o -path '*/bin/*' -o -path '*/obj/*' -o -path '*/dist/*' -o -path '*/coverage/*' -o -path '*/output/*' \) -prune -o \ -name '*.sln' ! -name 'StellaOps.sln' -print | sort ) if [[ ${#SOLUTIONS[@]} -eq 0 ]]; then echo "ERROR: No solution files found under src/." >&2 exit 1 fi echo "Found ${#SOLUTIONS[@]} solution(s) to build." echo "" build_pass=() build_fail=() test_pass=() test_fail=() for sln in "${SOLUTIONS[@]}"; do rel="${sln#"$REPO_ROOT/"}" echo "--- BUILD: $rel ---" if dotnet build "$sln" --configuration "$CONFIGURATION" --nologo -v quiet; then build_pass+=("$rel") else build_fail+=("$rel") echo " FAILED" continue fi if $RUN_TESTS; then echo "--- TEST: $rel ---" if dotnet test "$sln" --configuration "$CONFIGURATION" --nologo --no-build -v quiet; then test_pass+=("$rel") else test_fail+=("$rel") echo " TEST FAILED" fi fi done echo "" echo "========== Summary ==========" echo "Build passed : ${#build_pass[@]}" if [[ ${#build_fail[@]} -gt 0 ]]; then echo "Build failed : ${#build_fail[@]}" for f in "${build_fail[@]}"; do echo " - $f"; done fi if $RUN_TESTS; then echo "Test passed : ${#test_pass[@]}" if [[ ${#test_fail[@]} -gt 0 ]]; then echo "Test failed : ${#test_fail[@]}" for f in "${test_fail[@]}"; do echo " - $f"; done fi fi if [[ ${#build_fail[@]} -gt 0 ]] || [[ ${#test_fail[@]} -gt 0 ]]; then exit 1 fi