修复构建与后端测试并发冲突并补充迁移验收记录
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-08 18:59:50 +08:00
1 parent b7d4805402
commit c33b8bbc2f
6 files changed
+232 -14

No files matched your search

+7
View File
@@ -2,6 +2,9 @@
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
. (Join-Path $PSScriptRoot 'workspace-lock.ps1')
$workspaceLock = Enter-SmailWorkspaceLock -Root $root
try {
$fingerprint = & node (Join-Path $PSScriptRoot 'build-state.mjs') fingerprint
if ($LASTEXITCODE -ne 0) { throw '无法计算源码指纹' }
$output = Join-Path $root 'out\backend'
@@ -62,3 +65,7 @@ if (-not $SkipFrontend) {
if ($LASTEXITCODE -ne 0) { throw '编译产物封存失败,禁止部署或启动旧包' }
}
Write-Output '构建完成:out/frontend、out/backend 和 out/plugins,包含三个内置插件。正式发行请使用 Makefile 的跨平台构建目标。'
} finally {
$workspaceLock.ReleaseMutex()
$workspaceLock.Dispose()
}
+31
View File
@@ -0,0 +1,31 @@
function Enter-SmailWorkspaceLock {
param([Parameter(Mandatory = $true)][string]$Root)
# 构建会归档 Go 嵌入资源,必须与同一源码目录的后端测试互斥。
# 使用系统互斥量,进程异常退出后也不会留下需要手工删除的锁文件。
$resolved = (Resolve-Path -LiteralPath $Root -ErrorAction Stop).ProviderPath
$identity = [IO.Path]::GetFullPath($resolved).TrimEnd('\').ToUpperInvariant()
$hash = [Security.Cryptography.SHA256]::Create()
try {
$digest = [BitConverter]::ToString($hash.ComputeHash([Text.Encoding]::UTF8.GetBytes($identity))).Replace('-', '')
} finally {
$hash.Dispose()
}
$mutex = [Threading.Mutex]::new($false, "Local\SmailWorkspace-$digest")
try {
$acquired = $false
try {
$acquired = $mutex.WaitOne(0)
} catch [Threading.AbandonedMutexException] {
# 上一个持有者异常退出时,系统已把互斥量交给当前线程。
$acquired = $true
}
if (-not $acquired) {
throw '同一工作区正在构建或执行后端测试,请等待结束后重试,避免嵌入资源被并发移动。'
}
return $mutex
} catch {
$mutex.Dispose()
throw
}
}