From 2c6bc2185cc81a2beebcaa6d0d305a126793b245 Mon Sep 17 00:00:00 2001 From: bridge Date: Thu, 30 Oct 2025 01:30:21 +0800 Subject: [PATCH] update pack --- tools/package/pack.ps1 | 89 ++++++++++++++++++++++++++++++------------ 1 file changed, 65 insertions(+), 24 deletions(-) diff --git a/tools/package/pack.ps1 b/tools/package/pack.ps1 index b7d611f..a0aa291 100644 --- a/tools/package/pack.ps1 +++ b/tools/package/pack.ps1 @@ -4,28 +4,20 @@ $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $RepoRoot = (Resolve-Path (Join-Path $ScriptDir "..\..")).Path -# Get Git TAG +# Get Git TAG (only the tag name, without commit hash or dirty flag) $tag = "" Push-Location $RepoRoot -# Get exact tag -$exact = & git describe --tags --abbrev=0 --exact-match -if ($LASTEXITCODE -eq 0 -and $exact) { - $tag = $exact.Trim() -} - -# Fallback: any readable description -if (-not $tag) { - $desc = & git describe --tags --dirty --always - if ($LASTEXITCODE -eq 0 -and $desc) { - $tag = $desc.Trim() - } +# Get the most recent tag name +$tagDesc = & git describe --tags --abbrev=0 2>$null +if ($LASTEXITCODE -eq 0 -and $tagDesc) { + $tag = $tagDesc.Trim() } Pop-Location if (-not $tag) { - Write-Error "Cannot get git tag. Please run in a Git repository." + Write-Error "Cannot get git tag. Please run in a Git repository with at least one tag." exit 1 } @@ -87,16 +79,65 @@ if (Test-Path $RuntimeHookPath) { # Call PyInstaller Push-Location $RepoRoot try { + $ErrorActionPreference = "Continue" # 允许继续执行即使有错误 & pyinstaller @argsList + $ErrorActionPreference = "Stop" # 恢复错误停止设置 } finally { Pop-Location -} - -# Copy cmd files -$CmdSrc = Join-Path $ScriptDir "set_env.cmd" -if (Test-Path $CmdSrc) { - Copy-Item -Path $CmdSrc -Destination $DistDir -Force -} - -Write-Host "Package completed: " (Resolve-Path $DistDir).Path -Write-Host "Executable directory: " (Join-Path $DistDir $AppName) \ No newline at end of file + + # 在 finally 块中执行后续操作,确保一定会执行 + Write-Host "`n=== Post-build processing ===" -ForegroundColor Green + + # Copy cmd files to exe directory + $CmdSrc = Join-Path $ScriptDir "set_env.cmd" + $ExeDir = Join-Path $DistDir $AppName + if ((Test-Path $CmdSrc) -and (Test-Path $ExeDir)) { + Copy-Item -Path $CmdSrc -Destination $ExeDir -Force + # Rename cmd file + $OldCmdPath = Join-Path $ExeDir "set_env.cmd" + $NewCmdPath = Join-Path $ExeDir "点击输入大模型密钥.cmd" + if (Test-Path $OldCmdPath) { + Move-Item -Path $OldCmdPath -Destination $NewCmdPath -Force + Write-Host "✓ Copied and renamed to 点击输入大模型密钥.cmd in exe directory" -ForegroundColor Green + } + } + + # Copy static and assets to exe directory + if (Test-Path $ExeDir) { + if (Test-Path $AssetsPath) { + Copy-Item -Path $AssetsPath -Destination $ExeDir -Recurse -Force + Write-Host "✓ Copied assets to exe directory" -ForegroundColor Green + } + + if (Test-Path $StaticPath) { + Copy-Item -Path $StaticPath -Destination $ExeDir -Recurse -Force + # 删除 local_config.yml + $LocalConfigPath = Join-Path $ExeDir "static\local_config.yml" + if (Test-Path $LocalConfigPath) { + Remove-Item -Path $LocalConfigPath -Force + Write-Host "✓ Copied static to exe directory (excluded local_config.yml)" -ForegroundColor Green + } else { + Write-Host "✓ Copied static to exe directory" -ForegroundColor Green + } + } + } + + # Clean up build and spec directories (delete entire directories) + $BuildDirRoot = Join-Path $RepoRoot "tmp\build" + if (Test-Path $BuildDirRoot) { + Remove-Item -Path $BuildDirRoot -Recurse -Force + Write-Host "✓ Deleted entire build directory: $BuildDirRoot" -ForegroundColor Green + } + + # $SpecDirRoot = Join-Path $RepoRoot "tmp\spec" + # if (Test-Path $SpecDirRoot) { + # Remove-Item -Path $SpecDirRoot -Recurse -Force + # Write-Host "✓ Deleted entire spec directory: $SpecDirRoot" -ForegroundColor Green + # } + + Write-Host "`n=== Package completed ===" -ForegroundColor Cyan + Write-Host "Distribution directory: " (Resolve-Path $DistDir).Path + if (Test-Path $ExeDir) { + Write-Host "Executable directory: " (Resolve-Path $ExeDir).Path + } +} \ No newline at end of file