From a992c7b079b14aa2f372ea2f27a32130618af8bb Mon Sep 17 00:00:00 2001 From: MayueCif Date: Thu, 25 Jun 2026 23:13:06 +0800 Subject: [PATCH] =?UTF-8?q?```=20build(windows):=20=E6=9B=B4=E6=96=B0=20Wi?= =?UTF-8?q?ndows=20=E5=AE=89=E8=A3=85=E7=A8=8B=E5=BA=8F=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 release.yml 工作流中添加四段数字版本号计算逻辑 - 修改 build-installer.ps1 脚本以生成符合要求的版本信息格式 - 在 MarketAssistant.iss 中新增 MyAppVersionInfo 定义 - 将 VersionInfoVersion 和 VersionInfoProductVersion 指向新的四段版本格式 - 移除预发布标识并确保版本号严格遵循 X.X.X.X 格式 - 添加版本信息验证和调试输出功能 ``` --- .github/workflows/release.yml | 8 ++++++++ scripts/windows/MarketAssistant.iss | 7 +++++-- scripts/windows/build-installer.ps1 | 10 +++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aa8d379..85020de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -80,9 +80,17 @@ jobs: APP_VERSION: ${{ steps.version.outputs.version }} run: | $version = $env:APP_VERSION + # 计算四段数字版本号 (X.X.X.X),供 VersionInfoVersion 使用 + # 去掉预发布标识 (如 1.0.0-beta -> 1.0.0),按点分割并补齐到四段 + $numericPart = ($version -split '[-+]')[0] + $parts = $numericPart -split '\.' + while ($parts.Count -lt 4) { $parts += '0' } + if ($parts.Count -gt 4) { $parts = $parts[0..3] } + $versionInfo = ($parts | ForEach-Object { if ([int]::TryParse($_, [ref]$null)) { [int]::Parse($_) } else { 0 } }) -join '.' $issFile = "scripts\windows\MarketAssistant.iss" $content = Get-Content $issFile -Raw $content = $content -replace '#define MyAppVersion ".*?"', "#define MyAppVersion `"$version`"" + $content = $content -replace '#define MyAppVersionInfo ".*?"', "#define MyAppVersionInfo `"$versionInfo`"" Set-Content $issFile -Value $content -NoNewline & "${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe" $issFile diff --git a/scripts/windows/MarketAssistant.iss b/scripts/windows/MarketAssistant.iss index 7045aeb..eb83d1f 100644 --- a/scripts/windows/MarketAssistant.iss +++ b/scripts/windows/MarketAssistant.iss @@ -4,6 +4,9 @@ #define MyAppName "Market Assistant" #define MyAppVersion "1.0.0" +; VersionInfoVersion / VersionInfoProductVersion 要求严格四段数字格式 X.X.X.X +; MyAppVersion 可能为三段(1.0.0)或含预发布标识(1.0.0-beta),此处单独定义四段版本 +#define MyAppVersionInfo "1.0.0.0" #define MyAppPublisher "MarketAssistant Team" #define MyAppURL "https://github.com/X2Agent/MarketAssistant" #define MyAppExeName "MarketAssistant.exe" @@ -34,12 +37,12 @@ ArchitecturesAllowed=x64 ArchitecturesInstallIn64BitMode=x64 ; 版本信息 -VersionInfoVersion={#MyAppVersion} +VersionInfoVersion={#MyAppVersionInfo} VersionInfoCompany={#MyAppPublisher} VersionInfoDescription={#MyAppName} Installer VersionInfoCopyright=Copyright (C) 2026 {#MyAppPublisher} VersionInfoProductName={#MyAppName} -VersionInfoProductVersion={#MyAppVersion} +VersionInfoProductVersion={#MyAppVersionInfo} ; UI 配置 UninstallDisplayIcon={app}\{#MyAppExeName} diff --git a/scripts/windows/build-installer.ps1 b/scripts/windows/build-installer.ps1 index 4e10dfe..768b0c4 100644 --- a/scripts/windows/build-installer.ps1 +++ b/scripts/windows/build-installer.ps1 @@ -56,10 +56,18 @@ Write-Host "" $issFile = "scripts\windows\MarketAssistant.iss" if ($Version) { Write-Host "📝 Updating version to $Version..." -ForegroundColor Yellow + # 计算四段数字版本号 (X.X.X.X),供 VersionInfoVersion 使用 + # 去掉预发布标识 (如 1.0.0-beta -> 1.0.0),按点分割并补齐到四段 + $numericPart = ($Version -split '[-+]')[0] + $parts = $numericPart -split '\.' + while ($parts.Count -lt 4) { $parts += '0' } + if ($parts.Count -gt 4) { $parts = $parts[0..3] } + $versionInfo = ($parts | ForEach-Object { if ([int]::TryParse($_, [ref]$null)) { [int]::Parse($_) } else { 0 } }) -join '.' $issContent = Get-Content $issFile -Raw $issContent = $issContent -replace '#define MyAppVersion ".*?"', "#define MyAppVersion `"$Version`"" + $issContent = $issContent -replace '#define MyAppVersionInfo ".*?"', "#define MyAppVersionInfo `"$versionInfo`"" Set-Content $issFile -Value $issContent -NoNewline - Write-Host "✓ Version updated" -ForegroundColor Green + Write-Host "✓ Version updated (display: $Version, version info: $versionInfo)" -ForegroundColor Green Write-Host "" }