[CmdletBinding()] param() $ErrorActionPreference = "Stop" $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path $buildRoot = Join-Path $repoRoot "build\pyinstaller" $distRoot = Join-Path $repoRoot "dist\DxDesignerTools" $releaseBase = Join-Path $repoRoot "release" $releaseRoot = Join-Path $releaseBase "DxDesigner效率工具" $archivePath = Join-Path $releaseBase "DxDesigner效率工具_Win11_x64.zip" $manifestPath = Join-Path $releaseBase "SHA256SUMS.txt" $versionFile = Join-Path $releaseRoot "version.json" $updateManifestFile = Join-Path $releaseRoot "update-manifest.template.json" function Assert-RepositoryChild { param([Parameter(Mandatory = $true)][string]$Path) $fullPath = [IO.Path]::GetFullPath($Path) $fullRoot = [IO.Path]::GetFullPath($repoRoot).TrimEnd('\') + '\' if (-not $fullPath.StartsWith($fullRoot, [StringComparison]::OrdinalIgnoreCase)) { throw "Refusing to modify path outside repository: $fullPath" } } foreach ($path in @($buildRoot, $distRoot, $releaseRoot, $archivePath, $manifestPath)) { Assert-RepositoryChild -Path $path } $pythonInfo = & py -3.12 -c "import struct,sys; print(str(sys.version_info.major)+'.'+str(sys.version_info.minor)+'|'+str(struct.calcsize('P')*8))" if ($LASTEXITCODE -ne 0 -or $pythonInfo.Trim() -ne "3.12|64") { throw "Build requires 64-bit Python 3.12." } $pythonExe = (& py -3.12 -c "import sys; print(sys.executable)").Trim() if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $pythonExe -PathType Leaf)) { throw "Could not resolve the Python 3.12 executable." } & $pythonExe -c "import PyInstaller, PySide6, qtawesome, pypdf, win32job" if ($LASTEXITCODE -ne 0) { throw "Build dependencies are missing. Install the project build extras before running this script." } foreach ($path in @($buildRoot, $distRoot, $releaseRoot)) { if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path -Recurse -Force } } foreach ($path in @($archivePath, $manifestPath)) { if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path -Force } } New-Item -ItemType Directory -Path $releaseBase -Force | Out-Null $pyInstallerArgs = @( "-m", "PyInstaller", "--noconfirm", "--clean", "--workpath", $buildRoot, "--distpath", (Split-Path -Parent $distRoot), (Join-Path $PSScriptRoot "DxDesignerTools.spec") ) $pythonRoot = Split-Path -Parent $pythonExe $windowsRoot = if ([string]::IsNullOrWhiteSpace($env:WINDIR)) { "C:\Windows" } else { $env:WINDIR } $buildPath = @( $pythonRoot, (Join-Path $pythonRoot "Scripts"), (Join-Path $windowsRoot "System32"), $windowsRoot, (Join-Path $windowsRoot "System32\Wbem") ) -join ";" $originalPath = $env:PATH try { $env:PATH = $buildPath & $pythonExe @pyInstallerArgs if ($LASTEXITCODE -ne 0) { throw "PyInstaller build failed." } } finally { $env:PATH = $originalPath } Copy-Item -LiteralPath $distRoot -Destination $releaseRoot -Recurse Copy-Item -LiteralPath (Join-Path $repoRoot "integration\dxdesigner795\MenuAdd.vbs") -Destination (Join-Path $releaseRoot "MenuAdd.vbs") Copy-Item -LiteralPath (Join-Path $repoRoot "integration\dxdesigner795\DesignBridge.vbs") -Destination (Join-Path $releaseRoot "DesignBridge.vbs") Copy-Item -LiteralPath (Join-Path $repoRoot "integration\dxdesigner795\CompatibilityProbe.vbs") -Destination (Join-Path $releaseRoot "CompatibilityProbe.vbs") Copy-Item -LiteralPath (Join-Path $repoRoot "integration\dxdesigner795\PdfSaveListener.vbs") -Destination (Join-Path $releaseRoot "PdfSaveListener.vbs") Copy-Item -LiteralPath (Join-Path $repoRoot "integration\dxdesigner795\LoadMenu.vbs") -Destination (Join-Path $releaseRoot "LoadMenu.vbs") $runtimeVbs = Join-Path $releaseRoot "_runtime\vbs" New-Item -ItemType Directory -Path $runtimeVbs -Force | Out-Null Copy-Item -LiteralPath (Join-Path $repoRoot "integration\dxdesigner795\BridgeCommon.vbs") -Destination (Join-Path $runtimeVbs "BridgeCommon.vbs") $coreSource = Join-Path $repoRoot "integration\dxdesigner795\core" New-Item -ItemType Directory -Path $runtimeVbs -Force | Out-Null Copy-Item -Path (Join-Path $coreSource "*.vbs") -Destination $runtimeVbs $expeditionRoot = Join-Path $releaseRoot "expedition" New-Item -ItemType Directory -Path $expeditionRoot -Force | Out-Null Copy-Item -LiteralPath (Join-Path $repoRoot "integration\dxdesigner795\expedition\ExpeditionBridge.vbs") -Destination (Join-Path $expeditionRoot "ExpeditionBridge.vbs") $templatesRoot = Join-Path $releaseRoot "templates" New-Item -ItemType Directory -Path $templatesRoot -Force | Out-Null Copy-Item -LiteralPath (Join-Path $repoRoot "integration\dxdesigner795\templates\BOM模板.xls") -Destination (Join-Path $templatesRoot "BOM模板.xls") $docsRoot = Join-Path $releaseRoot "docs" New-Item -ItemType Directory -Path $docsRoot -Force | Out-Null $guideSource = Join-Path $repoRoot "docs\user\DxDesigner_7.9.5_自动位号工具使用说明_v0.5.docx" $guideDestination = Join-Path $docsRoot "DxDesigner_7.9.5_自动位号工具使用说明.docx" Copy-Item -LiteralPath $guideSource -Destination $guideDestination $pdfGuideDestination = Join-Path $docsRoot "PDF导出.md" Copy-Item -LiteralPath (Join-Path $repoRoot "docs\user\PDF_export.md") -Destination $pdfGuideDestination Copy-Item -LiteralPath (Join-Path $repoRoot "docs\user\一叶知秋_重构版_更新说明.md") -Destination (Join-Path $docsRoot "更新说明.md") $env:PYTHONPATH = Join-Path $repoRoot "src" $productVersion = (& $pythonExe -c "import dx_productivity; print(dx_productivity.__version__)").Trim() if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($productVersion)) { throw "Could not read dx_productivity.__version__ from the source tree." } Remove-Item Env:\PYTHONPATH -ErrorAction SilentlyContinue $versionPayload = [ordered]@{ product = "yiyezhqiu-refactored" display_name = "一叶知秋_重构版" version = $productVersion } [IO.File]::WriteAllText($versionFile, ($versionPayload | ConvertTo-Json), [Text.UTF8Encoding]::new($false)) $updatePayload = [ordered]@{ product = "yiyezhqiu-refactored" version = $productVersion channel = "stable" min_supported_version = "0.1.0" package_url = "" sha256 = "" release_notes = "" published_at = (Get-Date).ToUniversalTime().ToString("yyyy-MM-dd") signature = "" } [IO.File]::WriteAllText($updateManifestFile, ($updatePayload | ConvertTo-Json), [Text.UTF8Encoding]::new($false)) $expected = @( (Join-Path $releaseRoot "DxDesignerTools.exe"), (Join-Path $releaseRoot "_runtime\python312.dll"), (Join-Path $releaseRoot "MenuAdd.vbs"), (Join-Path $releaseRoot "DesignBridge.vbs"), (Join-Path $releaseRoot "CompatibilityProbe.vbs"), (Join-Path $releaseRoot "PdfSaveListener.vbs"), (Join-Path $releaseRoot "LoadMenu.vbs"), (Join-Path $releaseRoot "_runtime\vbs\BridgeCommon.vbs"), (Join-Path $releaseRoot "_runtime\vbs\Snapshot.vbs"), (Join-Path $releaseRoot "_runtime\vbs\Transaction.vbs"), (Join-Path $releaseRoot "_runtime\vbs\Mailbox.vbs"), (Join-Path $releaseRoot "_runtime\vbs\BomExport.vbs"), (Join-Path $releaseRoot "templates\BOM模板.xls"), (Join-Path $releaseRoot "expedition\ExpeditionBridge.vbs"), (Join-Path $docsRoot "DxDesigner_7.9.5_自动位号工具使用说明.docx"), $pdfGuideDestination, $versionFile, $updateManifestFile ) foreach ($path in $expected) { if (-not (Test-Path -LiteralPath $path -PathType Leaf)) { throw "Release file is missing: $path" } } Compress-Archive -LiteralPath $releaseRoot -DestinationPath $archivePath -CompressionLevel Optimal $archiveHash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant() $manifest = "$archiveHash *DxDesigner效率工具_Win11_x64.zip" + [Environment]::NewLine [IO.File]::WriteAllText($manifestPath, $manifest, [Text.UTF8Encoding]::new($false)) Write-Output "RELEASE_ROOT=$releaseRoot" Write-Output "ARCHIVE=$archivePath" Write-Output "SHA256=$archiveHash"