chore: baseline md-preview 1.4.2 + agent workspace
This commit is contained in:
90
agent/scripts/build.ps1
Normal file
90
agent/scripts/build.ps1
Normal file
@@ -0,0 +1,90 @@
|
||||
#requires -Version 5.1
|
||||
<#
|
||||
MD Preview 发布构建脚本
|
||||
固定产物:D:\Scripts\md-preview\MD-Preview-windows-x64.exe
|
||||
|
||||
运行环境:普通 PowerShell(Medium),或 DSH 的 danger-full-access。
|
||||
workspace-write 是 Low 完整性级别,写不动本目录(EPERM / os error 5)。
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$OutputPath = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe',
|
||||
[switch]$SkipTests
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
|
||||
Set-Location $repoRoot
|
||||
|
||||
$cargo = Join-Path $env:USERPROFILE '.cargo\bin\cargo.exe'
|
||||
if (-not (Test-Path $cargo)) {
|
||||
$cargo = (Get-Command cargo -ErrorAction Stop).Source
|
||||
}
|
||||
|
||||
function Step([string]$text) { Write-Host ('==> ' + $text) -ForegroundColor Cyan }
|
||||
|
||||
function Assert-TargetNotRunning([string]$path) {
|
||||
$ids = @()
|
||||
foreach ($p in (Get-Process -ErrorAction SilentlyContinue)) {
|
||||
$pPath = $null
|
||||
try { $pPath = $p.Path } catch { }
|
||||
if ($pPath -eq $path) { $ids += $p.Id }
|
||||
}
|
||||
if ($ids.Count -gt 0) {
|
||||
throw ('MD Preview 正在运行(PID ' + ($ids -join ', ') + '),请先关闭窗口再构建。')
|
||||
}
|
||||
}
|
||||
|
||||
Assert-TargetNotRunning $OutputPath
|
||||
|
||||
if (-not $SkipTests) {
|
||||
Step 'cargo test'
|
||||
& $cargo test
|
||||
if ($LASTEXITCODE -ne 0) { throw 'cargo test failed' }
|
||||
}
|
||||
|
||||
Step 'cargo build --release'
|
||||
& $cargo build --release
|
||||
if ($LASTEXITCODE -ne 0) { throw 'cargo build failed' }
|
||||
|
||||
$built = Join-Path $repoRoot 'target\release\md-preview.exe'
|
||||
if (-not (Test-Path $built)) { throw ('missing build output: ' + $built) }
|
||||
|
||||
Step ('copy -> ' + $OutputPath)
|
||||
$outDir = Split-Path -Parent $OutputPath
|
||||
if (-not (Test-Path $outDir)) { New-Item -ItemType Directory -Path $outDir | Out-Null }
|
||||
Assert-TargetNotRunning $OutputPath
|
||||
try {
|
||||
Copy-Item $built $OutputPath -Force -ErrorAction Stop
|
||||
} catch {
|
||||
throw ('复制失败(目标可能被占用):' + $_.Exception.Message)
|
||||
}
|
||||
|
||||
$info = Get-Item $OutputPath
|
||||
$hash = (Get-FileHash $OutputPath -Algorithm SHA256).Hash
|
||||
Write-Host ('size : {0:N0} bytes' -f $info.Length)
|
||||
Write-Host ('sha256 : ' + $hash)
|
||||
Write-Host ('version : ' + $info.VersionInfo.FileVersion)
|
||||
|
||||
Step 'check removed update strings'
|
||||
$bytes = [IO.File]::ReadAllBytes($OutputPath)
|
||||
$ascii = [Text.Encoding]::ASCII.GetString($bytes)
|
||||
$forbidden = @('api.github', 'btn-update', 'Check for Updates', 'powershell', 'update-check-result', 'open-url')
|
||||
$bad = @()
|
||||
foreach ($needle in $forbidden) {
|
||||
$count = ([regex]::Matches($ascii, [regex]::Escape($needle), 'IgnoreCase')).Count
|
||||
Write-Host (' {0,-20} {1}' -f $needle, $count)
|
||||
if ($count -ne 0) { $bad += $needle }
|
||||
}
|
||||
if ($bad.Count -gt 0) { throw ('removed features still present: ' + ($bad -join ', ')) }
|
||||
|
||||
Step 'check integrity level'
|
||||
$acl = (icacls $OutputPath | Out-String)
|
||||
if ($acl -match 'Medium Mandatory Level') {
|
||||
Write-Host ' Medium - OK'
|
||||
} else {
|
||||
Write-Warning '不是 Medium:启动时可能报 os error 5,见 agent/docs/HANDOFF.md 第 4 节'
|
||||
}
|
||||
|
||||
Write-Host ''
|
||||
Write-Host ('DONE ' + $OutputPath) -ForegroundColor Green
|
||||
Reference in New Issue
Block a user