Files
Genarrative/server-rs/scripts/check.ps1

69 lines
2.2 KiB
PowerShell

[CmdletBinding()]
param(
[Alias("h")]
[switch]$Help,
[Alias("Package")]
[string]$Crate = ""
)
$ErrorActionPreference = "Stop"
function Write-Usage {
@(
'Usage:'
' ./server-rs/scripts/check.ps1'
' ./server-rs/scripts/check.ps1 -Crate 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 -Crate to target one workspace crate 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($Crate)) {
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 crate: $Crate"
Write-Host "[server-rs:check] step: cargo clippy -p $Crate --all-targets --all-features -D warnings"
cargo clippy -p $Crate --manifest-path $manifestPath --all-targets --all-features -- -D warnings
Write-Host "[server-rs:check] step: cargo check -p $Crate"
cargo check -p $Crate --manifest-path $manifestPath
Write-Host "[server-rs:check] step: cargo test -p $Crate"
cargo test -p $Crate --manifest-path $manifestPath
}
}
finally {
Pop-Location
}