Skip to main content

max / makenotwork

3.2 KB · 119 lines History Blame Raw
1 #!/bin/bash
2 # CI script for makenotwork — replaces .build.yml (Sourcehut).
3 # Run on astra: /home/max/staging/run-ci.sh [filter]
4 #
5 # Runs: cargo check, cargo test --lib, cargo test --test integration,
6 # cargo clippy, cargo audit (if installed).
7 #
8 # Usage:
9 # ./run-ci.sh # full CI
10 # ./run-ci.sh auth # only tests matching "auth"
11
12 set -euo pipefail
13
14 # Ensure ~/.cargo/bin is in PATH (SSH non-login shells may not source .profile)
15 export PATH="$HOME/.cargo/bin:$PATH"
16
17 SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
18 PROJECT_DIR="${SCRIPT_DIR}"
19
20 # Detect project directory layout
21 if [ -d "$SCRIPT_DIR/makenotwork/src" ]; then
22 # Rsync'd staging layout (e.g., ~/staging/makenotwork/)
23 PROJECT_DIR="$SCRIPT_DIR/makenotwork"
24 fi
25
26 cd "$PROJECT_DIR"
27
28 export DATABASE_URL="${DATABASE_URL:-postgres:///makenotwork_staging}"
29 export TEST_DATABASE_URL="${TEST_DATABASE_URL:-postgres:///postgres}"
30 export RUST_TEST_THREADS="${RUST_TEST_THREADS:-8}"
31 export CARGO_INCREMENTAL=0
32 export RUST_BACKTRACE=1
33
34 FILTER="${1:-}"
35 FAILURES=()
36 PASS=()
37
38 run_step() {
39 local name="$1"
40 shift
41 echo ""
42 echo "========================================"
43 echo " $name"
44 echo "========================================"
45 echo ""
46 if "$@"; then
47 PASS+=("$name")
48 else
49 FAILURES+=("$name")
50 echo "FAILED: $name"
51 fi
52 }
53
54 cleanup_test_dbs() {
55 echo "Cleaning up orphaned test databases..."
56 sudo -u postgres psql -Atc "SELECT datname FROM pg_database WHERE datname LIKE 'test_%';" 2>/dev/null | while read -r db; do
57 sudo -u postgres psql -c "DROP DATABASE IF EXISTS \"$db\";" 2>/dev/null || true
58 done
59 }
60
61 # Pre-cleanup
62 cleanup_test_dbs
63
64 # Step 1: Compilation check
65 run_step "cargo check" cargo check --features fast-tests
66
67 # Step 2: Unit tests
68 if [ -n "$FILTER" ]; then
69 run_step "cargo test --lib ($FILTER)" cargo test --features fast-tests --lib "$FILTER"
70 else
71 run_step "cargo test --lib" cargo test --features fast-tests --lib
72 fi
73
74 # Step 3: Integration tests
75 if [ -n "$FILTER" ]; then
76 run_step "cargo test --test integration ($FILTER)" cargo test --features fast-tests --test integration "$FILTER" -- --test-threads=8
77 else
78 run_step "cargo test --test integration" cargo test --features fast-tests --test integration -- --test-threads=8
79 fi
80
81 # Step 4: Clippy
82 run_step "cargo clippy" cargo clippy --features fast-tests --all-targets -- -D warnings
83
84 # Step 5: Security audit (optional)
85 if command -v cargo-audit &>/dev/null; then
86 # Ignore known unfixable advisories:
87 # RUSTSEC-2023-0071: rsa via sqlx-mysql (MNW uses Postgres, not affected)
88 run_step "cargo audit" cargo audit --ignore RUSTSEC-2023-0071
89 else
90 echo ""
91 echo "[skip] cargo-audit not installed (cargo install cargo-audit)"
92 fi
93
94 # Post-cleanup
95 cleanup_test_dbs
96
97 # Summary
98 echo ""
99 echo "========================================"
100 echo " CI Summary"
101 echo "========================================"
102 echo ""
103
104 for step in "${PASS[@]}"; do
105 echo " PASS $step"
106 done
107 for step in "${FAILURES[@]+"${FAILURES[@]}"}"; do
108 echo " FAIL $step"
109 done
110
111 echo ""
112 if [ ${#FAILURES[@]} -eq 0 ]; then
113 echo "All steps passed."
114 exit 0
115 else
116 echo "${#FAILURES[@]} step(s) failed."
117 exit 1
118 fi
119