79 lines
2.4 KiB
Bash
79 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
fail() {
|
|
printf 'error: %s\n' "$*" >&2
|
|
exit 1
|
|
}
|
|
|
|
if [[ -f "$SCRIPT_DIR/Cargo.toml" ]]; then
|
|
ROOT="$SCRIPT_DIR"
|
|
elif [[ -f "$SCRIPT_DIR/../Cargo.toml" ]]; then
|
|
ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
|
|
else
|
|
fail "Cargo.toml not found next to the script or one directory above it"
|
|
fi
|
|
cd "$ROOT"
|
|
|
|
command -v cargo >/dev/null 2>&1 || fail "Rust/Cargo is required"
|
|
command -v rustc >/dev/null 2>&1 || fail "rustc is required"
|
|
command -v python3 >/dev/null 2>&1 || fail "Python 3.10+ is required"
|
|
command -v cc >/dev/null 2>&1 || fail "a C compiler/linker (cc) is required"
|
|
|
|
python3 - <<'PY'
|
|
import sys
|
|
if sys.version_info < (3, 10):
|
|
raise SystemExit("error: Python 3.10+ is required")
|
|
PY
|
|
|
|
[[ -f Cargo.toml ]] || fail "Cargo.toml not found; run this script from the RustProxy source tree"
|
|
[[ -f scripts/preflight.py ]] || fail "scripts/preflight.py not found"
|
|
[[ -f scripts/version.py ]] || fail "scripts/version.py not found"
|
|
|
|
VERSION="$(python3 scripts/version.py)"
|
|
printf 'Validating RustProxy %s\n' "$VERSION"
|
|
|
|
# Project-owned source/layout validation.
|
|
python3 scripts/preflight.py
|
|
python3 scripts/build/panel_css.py --check
|
|
|
|
if [[ ! -f Cargo.lock ]]; then
|
|
printf 'Cargo.lock not found - generating it...\n'
|
|
cargo generate-lockfile
|
|
fi
|
|
|
|
# Rust quality gates.
|
|
cargo fmt --all -- --check
|
|
cargo check --locked --all-targets
|
|
cargo test --locked --all-targets
|
|
cargo clippy --locked --all-targets -- -D warnings
|
|
cargo build --release --locked
|
|
|
|
# The Docker discovery agent is shipped with the source tree, but is a separate Go module.
|
|
# Set CHECK_DOCKER_AGENT=0 when intentionally validating only the Rust binary.
|
|
if [[ -f "$ROOT/docker-agent/go.mod" && "${CHECK_DOCKER_AGENT:-1}" != "0" ]]; then
|
|
command -v go >/dev/null 2>&1 || fail "Go is required to validate docker-agent (or set CHECK_DOCKER_AGENT=0)"
|
|
(
|
|
cd "$ROOT/docker-agent"
|
|
go test ./...
|
|
go build ./...
|
|
)
|
|
fi
|
|
|
|
TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}"
|
|
if [[ "$TARGET_DIR" != /* ]]; then
|
|
TARGET_DIR="$ROOT/$TARGET_DIR"
|
|
fi
|
|
BIN="$TARGET_DIR/release/rust-proxy"
|
|
|
|
[[ -x "$BIN" ]] || fail "RustProxy binary was not produced: $BIN"
|
|
|
|
ACTUAL_VERSION="$($BIN --version)"
|
|
printf '%s\n' "$ACTUAL_VERSION"
|
|
[[ "$ACTUAL_VERSION" == *"$VERSION"* ]] || fail "binary version does not match Cargo.toml ($VERSION)"
|
|
|
|
printf 'Built RustProxy: %s\n' "$BIN"
|
|
printf 'Cargo.lock retained: %s\n' "$ROOT/Cargo.lock"
|