chore: switch to Low workspace and Nutstore-only publish

- build.ps1: dev build only; no copy to a fixed exe
- publish.ps1: user-run Medium publish to Nutstore
- docs: workspace stays D:\Scripts\md-preview, repo under AgentLowWorking
- .gitignore: local test/ scratch directory
This commit is contained in:
2026-11-02 01:26:49 +08:00
parent 301e042bec
commit d2b1630a35
10 changed files with 433 additions and 194 deletions

View File

@@ -1,14 +1,13 @@
#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)。
MD Preview 开发构建(DSH workspace-write / Low 完整性可运行)
- cargo test + cargo build --release
- 只做校验,不复制到任何固定 exe 路径
- 产物:target\release\md-preview.exe(Low)
- 发布:用户在自己的普通 PowerShell 里运行 agent\scripts\publish.ps1
#>
[CmdletBinding()]
param(
[string]$OutputPath = 'D:\Scripts\md-preview\MD-Preview-windows-x64.exe',
[switch]$SkipTests
)
@@ -16,7 +15,7 @@ $ErrorActionPreference = 'Stop'
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
Set-Location $repoRoot
# 工作区规则(agent/AGENTS.md):构建/测试的临时文件也留在 target\ 下,不污染 %TEMP%。
# 工作区规则(agent/AGENTS.md):临时文件留在 target\ 下,不污染 %TEMP%。
$tmpRoot = Join-Path $repoRoot 'target\tmp'
New-Item -ItemType Directory -Force $tmpRoot | Out-Null
$env:TEMP = $tmpRoot
@@ -29,51 +28,49 @@ if (-not (Test-Path $cargo)) {
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 }
function Invoke-Cargo([string[]]$arguments) {
$previous = $ErrorActionPreference
$code = 0
try {
# cargo 把进度/警告写到 stderr;Stop 会把它们当成终止错误
$ErrorActionPreference = 'Continue'
& $cargo @arguments
$code = $LASTEXITCODE
} finally {
$ErrorActionPreference = $previous
}
if ($ids.Count -gt 0) {
throw ('MD Preview 正在运行(PID ' + ($ids -join ', ') + '),请先关闭窗口再构建。')
if ($code -ne 0) {
throw ('cargo ' + ($arguments -join ' ') + ' failed with exit code ' + $code)
}
}
Assert-TargetNotRunning $OutputPath
$built = Join-Path $repoRoot 'target\release\md-preview.exe'
$running = @()
foreach ($process in (Get-Process -ErrorAction SilentlyContinue)) {
$path = $null
try { $path = $process.Path } catch { }
if ($path -eq $built) { $running += [string]$process.Id }
}
if ($running.Count -gt 0) {
throw ('开发版 MD Preview 正在运行(PID ' + ($running -join ', ') + '),请先关闭。')
}
if (-not $SkipTests) {
Step 'cargo test'
& $cargo test
if ($LASTEXITCODE -ne 0) { throw 'cargo test failed' }
Invoke-Cargo @('test')
}
Step 'cargo build --release'
& $cargo build --release
if ($LASTEXITCODE -ne 0) { throw 'cargo build failed' }
Invoke-Cargo @('build', '--release')
$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)
$info = Get-Item $built
$hash = (Get-FileHash $built -Algorithm SHA256).Hash
Step 'check removed update strings'
$bytes = [IO.File]::ReadAllBytes($OutputPath)
$bytes = [IO.File]::ReadAllBytes($built)
$ascii = [Text.Encoding]::ASCII.GetString($bytes)
$forbidden = @('api.github', 'btn-update', 'Check for Updates', 'powershell', 'update-check-result', 'open-url')
$bad = @()
@@ -84,13 +81,14 @@ foreach ($needle in $forbidden) {
}
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 节'
}
Step 'report'
$acl = (icacls $built | Out-String)
$integrity = 'Unknown'
if ($acl -match 'Mandatory Label\\(Low|Medium|High) Mandatory Level') { $integrity = $Matches[1] }
Write-Host ('output : ' + $built)
Write-Host ('size : {0:N0} bytes' -f $info.Length)
Write-Host ('sha256 : ' + $hash)
Write-Host ('version : ' + $info.VersionInfo.FileVersion)
Write-Host ('integrity : ' + $integrity + ' (workspace-write builds are Low)')
Write-Host ''
Write-Host ('DONE ' + $OutputPath) -ForegroundColor Green
Write-Host 'DONE (build only). Publish: .\agent\scripts\publish.ps1 (normal PowerShell, Medium)' -ForegroundColor Green