| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
set -euo pipefail |
| 13 |
|
| 14 |
|
| 15 |
export PATH="$HOME/.cargo/bin:$PATH" |
| 16 |
|
| 17 |
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 18 |
PROJECT_DIR="${SCRIPT_DIR}" |
| 19 |
|
| 20 |
|
| 21 |
if [ -d "$SCRIPT_DIR/makenotwork/src" ]; then |
| 22 |
|
| 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 |
|
| 62 |
cleanup_test_dbs |
| 63 |
|
| 64 |
|
| 65 |
run_step "cargo check" cargo check --features fast-tests |
| 66 |
|
| 67 |
|
| 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 |
|
| 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 |
|
| 82 |
run_step "cargo clippy" cargo clippy --features fast-tests --all-targets -- -D warnings |
| 83 |
|
| 84 |
|
| 85 |
if command -v cargo-audit &>/dev/null; then |
| 86 |
|
| 87 |
|
| 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 |
|
| 95 |
cleanup_test_dbs |
| 96 |
|
| 97 |
|
| 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 |
|