Files
full/scripts/verify-workspace.ps1
2026-09-22 21:15:34 +08:00

44 lines
1.5 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
[CmdletBinding()]
param(
[switch]$SkipVet
)
$ErrorActionPreference = "Stop"
$workspaceRoot = Split-Path -Parent $PSScriptRoot
Push-Location $workspaceRoot
try {
# 本地开发前提go.work 把共享 SDK 替换为工作区外的相对路径,缺少该目录时整个工作区都无法解析。
$sdkDir = [System.IO.Path]::GetFullPath((Join-Path $workspaceRoot "..\..\bsm-sdk\core"))
if (-not (Test-Path -Path $sdkDir -PathType Container)) {
throw "未找到共享 SDK 目录: $sdkDir`n本地开发前提不满足:请先将 bsm-sdk/core 检出到工作区上一级目录的同级路径,即 $sdkDir"
}
$unformatted = @(gofmt -l pkgs module scripts)
if ($unformatted.Count -gt 0) {
throw ("gofmt required:" + [Environment]::NewLine + ($unformatted -join [Environment]::NewLine))
}
$modules = @(go list -m -f '{{.Dir}}')
if ($LASTEXITCODE -ne 0 -or $modules.Count -eq 0) {
throw "未解析到任何工作区模块go list -m 可能失败或返回空列表"
}
foreach ($module in $modules) {
Write-Host "==> $module"
Push-Location $module
try {
if (-not $SkipVet) {
go vet ./...
if ($LASTEXITCODE -ne 0) { throw "go vet failed: $module" }
}
go test ./...
if ($LASTEXITCODE -ne 0) { throw "go test failed: $module" }
}
finally {
Pop-Location
}
}
}
finally {
Pop-Location
}