|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -u |
| 3 | +set -o pipefail |
| 4 | + |
| 5 | +# Mirror of GitHub Actions Rust CI, for local use. |
| 6 | +# Runs: |
| 7 | +# - cargo test (debug + release) on stable/beta/nightly (if installed) |
| 8 | +# - cargo fmt (nightly, --check) |
| 9 | +# - taplo fmt --check |
| 10 | +# - cargo clippy --all-targets --all-features -D warnings |
| 11 | +# - cargo doc with RUSTDOCFLAGS=-D warnings |
| 12 | +# - cargo tarpaulin (coverage) for package sql_docs |
| 13 | +# |
| 14 | +# Only prints full command output when a step fails. |
| 15 | + |
| 16 | +CARGO_TERM_COLOR=always |
| 17 | +export CARGO_TERM_COLOR |
| 18 | + |
| 19 | +LOG_DIR="$(mktemp -d -t rust-ci-logs-XXXXXX)" |
| 20 | +failed=0 |
| 21 | +step_index=0 |
| 22 | + |
| 23 | +cleanup() { |
| 24 | + rm -rf "$LOG_DIR" 2>/dev/null || true |
| 25 | +} |
| 26 | +trap cleanup EXIT |
| 27 | + |
| 28 | +run_step() { |
| 29 | + local name="$1" |
| 30 | + shift |
| 31 | + step_index=$((step_index + 1)) |
| 32 | + local log="$LOG_DIR/${step_index}_${name//[^A-Za-z0-9_.-]/_}.log" |
| 33 | + |
| 34 | + # Minimal noise on success: just a single line. |
| 35 | + echo "==> $name" |
| 36 | + if "$@" >"$log" 2>&1; then |
| 37 | + echo " OK" |
| 38 | + rm -f "$log" |
| 39 | + else |
| 40 | + echo " FAILED" |
| 41 | + echo "---- $name log ----" |
| 42 | + sed 's/^/ /' "$log" |
| 43 | + echo "-------------------" |
| 44 | + failed=1 |
| 45 | + fi |
| 46 | +} |
| 47 | + |
| 48 | +# --- Sanity checks --------------------------------------------------------- |
| 49 | + |
| 50 | +if ! command -v rustup >/dev/null 2>&1; then |
| 51 | + echo "rustup is required to run this script." |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +if ! command -v cargo >/dev/null 2>&1; then |
| 56 | + echo "cargo is required to run this script." |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | + |
| 60 | +# --- Test matrix: stable, beta, nightly ----------------------------------- |
| 61 | + |
| 62 | +for TOOLCHAIN in stable beta nightly; do |
| 63 | + if rustup toolchain list | grep -q "^$TOOLCHAIN"; then |
| 64 | + run_step "tests-${TOOLCHAIN}-debug" rustup run "$TOOLCHAIN" cargo test --verbose |
| 65 | + run_step "tests-${TOOLCHAIN}-release" rustup run "$TOOLCHAIN" cargo test --release --verbose |
| 66 | + else |
| 67 | + echo "==> Skipping tests for $TOOLCHAIN (toolchain not installed)" |
| 68 | + fi |
| 69 | +done |
| 70 | + |
| 71 | +# --- Rustfmt (nightly) ----------------------------------------------------- |
| 72 | + |
| 73 | +if rustup toolchain list | grep -q "^nightly"; then |
| 74 | + run_step "rustfmt-install-nightly" rustup component add --toolchain nightly rustfmt |
| 75 | + run_step "rustfmt-check" rustup run nightly cargo fmt --all -- --check |
| 76 | +else |
| 77 | + echo "==> Skipping rustfmt check (nightly toolchain not installed)" |
| 78 | +fi |
| 79 | + |
| 80 | +# --- Taplo (TOML formatting) ---------------------------------------------- |
| 81 | + |
| 82 | +if ! command -v taplo >/dev/null 2>&1; then |
| 83 | + # mirror GH action behavior: install taplo if missing |
| 84 | + run_step "install-taplo-cli" cargo install taplo-cli |
| 85 | +fi |
| 86 | + |
| 87 | +if command -v taplo >/dev/null 2>&1; then |
| 88 | + run_step "taplo-fmt-check" taplo fmt --check |
| 89 | +else |
| 90 | + echo "==> Skipping taplo fmt check (taplo not available and install failed)" |
| 91 | +fi |
| 92 | + |
| 93 | +# --- Clippy (stable) ------------------------------------------------------- |
| 94 | + |
| 95 | +if rustup toolchain list | grep -q "^stable"; then |
| 96 | + run_step "clippy-install" rustup component add --toolchain stable clippy |
| 97 | + run_step "clippy-check" rustup run stable cargo clippy --all-targets --all-features -- -D warnings |
| 98 | +else |
| 99 | + echo "==> Skipping clippy (stable toolchain not installed)" |
| 100 | +fi |
| 101 | + |
| 102 | +# --- Docs (stable) --------------------------------------------------------- |
| 103 | + |
| 104 | +if rustup toolchain list | grep -q "^stable"; then |
| 105 | + run_step "doc-check" env RUSTDOCFLAGS="-D warnings" rustup run stable cargo doc --no-deps --document-private-items |
| 106 | +else |
| 107 | + echo "==> Skipping doc check (stable toolchain not installed)" |
| 108 | +fi |
| 109 | + |
| 110 | +# --- Coverage (tarpaulin) -------------------------------------------------- |
| 111 | + |
| 112 | +if ! command -v cargo-tarpaulin >/dev/null 2>&1; then |
| 113 | + run_step "install-tarpaulin" cargo install cargo-tarpaulin |
| 114 | +fi |
| 115 | + |
| 116 | +if command -v cargo-tarpaulin >/dev/null 2>&1; then |
| 117 | + run_step "coverage-tarpaulin" cargo tarpaulin --verbose --engine=llvm --all-features --timeout 120 --out xml -p sql_docs |
| 118 | +else |
| 119 | + echo "==> Skipping coverage (cargo-tarpaulin not available and install failed)" |
| 120 | +fi |
| 121 | + |
| 122 | +# --- Summary --------------------------------------------------------------- |
| 123 | + |
| 124 | +if [[ "$failed" -ne 0 ]]; then |
| 125 | + echo |
| 126 | + echo "❌ One or more steps failed." |
| 127 | +else |
| 128 | + echo |
| 129 | + echo "✅ All steps passed." |
| 130 | +fi |
| 131 | + |
| 132 | +exit "$failed" |
0 commit comments