build: add server-rs check scripts
This commit is contained in:
67
server-rs/scripts/check.ps1
Normal file
67
server-rs/scripts/check.ps1
Normal file
@@ -0,0 +1,67 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Alias("h")]
|
||||
[switch]$Help,
|
||||
[string]$Package = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Write-Usage {
|
||||
@(
|
||||
'Usage:'
|
||||
' ./server-rs/scripts/check.ps1'
|
||||
' ./server-rs/scripts/check.ps1 -Package api-server'
|
||||
''
|
||||
'Notes:'
|
||||
' 1. Run cargo fmt --all --check for the whole server-rs workspace'
|
||||
' 2. Run clippy/check/test for the whole workspace by default'
|
||||
' 3. Use -Package to target one workspace package for clippy/check/test'
|
||||
) -join [Environment]::NewLine
|
||||
}
|
||||
|
||||
if ($Help) {
|
||||
Write-Usage
|
||||
exit 0
|
||||
}
|
||||
|
||||
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$serverRsDir = Split-Path -Parent $scriptDir
|
||||
$manifestPath = Join-Path $serverRsDir "Cargo.toml"
|
||||
|
||||
if (-not (Test-Path $manifestPath)) {
|
||||
throw "Missing server-rs/Cargo.toml, cannot start check script."
|
||||
}
|
||||
|
||||
Write-Host "[server-rs:check] working dir: $serverRsDir"
|
||||
Write-Host "[server-rs:check] step: cargo fmt --all --check"
|
||||
|
||||
Push-Location $serverRsDir
|
||||
try {
|
||||
cargo fmt --all --check --manifest-path $manifestPath
|
||||
|
||||
if ([string]::IsNullOrWhiteSpace($Package)) {
|
||||
Write-Host "[server-rs:check] step: cargo clippy --workspace --all-targets --all-features -D warnings"
|
||||
cargo clippy --workspace --manifest-path $manifestPath --all-targets --all-features -- -D warnings
|
||||
|
||||
Write-Host "[server-rs:check] step: cargo check --workspace"
|
||||
cargo check --workspace --manifest-path $manifestPath
|
||||
|
||||
Write-Host "[server-rs:check] step: cargo test --workspace"
|
||||
cargo test --workspace --manifest-path $manifestPath
|
||||
}
|
||||
else {
|
||||
Write-Host "[server-rs:check] target package: $Package"
|
||||
Write-Host "[server-rs:check] step: cargo clippy -p $Package --all-targets --all-features -D warnings"
|
||||
cargo clippy -p $Package --manifest-path $manifestPath --all-targets --all-features -- -D warnings
|
||||
|
||||
Write-Host "[server-rs:check] step: cargo check -p $Package"
|
||||
cargo check -p $Package --manifest-path $manifestPath
|
||||
|
||||
Write-Host "[server-rs:check] step: cargo test -p $Package"
|
||||
cargo test -p $Package --manifest-path $manifestPath
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
60
server-rs/scripts/check.sh
Normal file
60
server-rs/scripts/check.sh
Normal 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
|
||||
Reference in New Issue
Block a user