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
|
||||
}
|
||||
Reference in New Issue
Block a user