build: add server-rs check scripts

This commit is contained in:
2026-04-21 01:48:33 +08:00
parent 6a560236f4
commit fdab91e54d
12 changed files with 178 additions and 26 deletions

View File

@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -euo pipefail
# 统一串联 Rust workspace 的格式、lint、编译与测试校验保证本地和 CI 使用同一条检查链路。
usage() {
cat <<'EOF'
用法:
./server-rs/scripts/check.sh
SERVER_RS_CHECK_PACKAGE=api-server ./server-rs/scripts/check.sh
说明:
1. 先执行整个 `server-rs` workspace 的 `cargo fmt --all --check`
2. 默认继续执行整个 workspace 的 `cargo clippy`、`cargo check`、`cargo test`
3. 可通过 `SERVER_RS_CHECK_PACKAGE` 将 clippy/check/test 收窄到单个 package
4. `cargo fmt --all --check` 始终覆盖整个 workspace避免多 package 下格式口径漂移
EOF
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
SERVER_RS_DIR="$(cd -- "${SCRIPT_DIR}/.." && pwd)"
MANIFEST_PATH="${SERVER_RS_DIR}/Cargo.toml"
if [[ ! -f "${MANIFEST_PATH}" ]]; then
echo "[server-rs:check] 未找到 ${MANIFEST_PATH},无法启动检查脚本。" >&2
exit 1
fi
echo "[server-rs:check] 工作目录: ${SERVER_RS_DIR}"
echo "[server-rs:check] 步骤: cargo fmt --all --check"
cd "${SERVER_RS_DIR}"
cargo fmt --all --check --manifest-path "${MANIFEST_PATH}"
if [[ -n "${SERVER_RS_CHECK_PACKAGE:-}" ]]; then
echo "[server-rs:check] 目标 package: ${SERVER_RS_CHECK_PACKAGE}"
echo "[server-rs:check] 步骤: cargo clippy -p ${SERVER_RS_CHECK_PACKAGE} --all-targets --all-features -D warnings"
cargo clippy -p "${SERVER_RS_CHECK_PACKAGE}" --manifest-path "${MANIFEST_PATH}" --all-targets --all-features -- -D warnings
echo "[server-rs:check] 步骤: cargo check -p ${SERVER_RS_CHECK_PACKAGE}"
cargo check -p "${SERVER_RS_CHECK_PACKAGE}" --manifest-path "${MANIFEST_PATH}"
echo "[server-rs:check] 步骤: cargo test -p ${SERVER_RS_CHECK_PACKAGE}"
cargo test -p "${SERVER_RS_CHECK_PACKAGE}" --manifest-path "${MANIFEST_PATH}"
else
echo "[server-rs:check] 步骤: cargo clippy --workspace --all-targets --all-features -D warnings"
cargo clippy --workspace --manifest-path "${MANIFEST_PATH}" --all-targets --all-features -- -D warnings
echo "[server-rs:check] 步骤: cargo check --workspace"
cargo check --workspace --manifest-path "${MANIFEST_PATH}"
echo "[server-rs:check] 步骤: cargo test --workspace"
cargo test --workspace --manifest-path "${MANIFEST_PATH}"
fi