feat(ci): 添加 Windows 单文件打包工作流
添加 Enigma Virtual Box 和 7-Zip 备选方案,用于将 Flutter Windows 应用打包为单文件 EXE 包含自动化脚本和文档说明,优化构建产物分发
This commit is contained in:
@@ -314,3 +314,176 @@ jobs:
|
||||
with:
|
||||
name: windows-release-build
|
||||
path: build/windows/x64/runner/Release/
|
||||
|
||||
- name: Download Enigma Virtual Box
|
||||
shell: powershell
|
||||
run: |
|
||||
Write-Host "下载 Enigma Virtual Box..."
|
||||
$enigmaUrl = "https://enigmaprotector.com/assets/files/enigmavb.exe"
|
||||
$enigmaPath = "C:\enigmavb.exe"
|
||||
|
||||
try {
|
||||
Invoke-WebRequest -Uri $enigmaUrl -OutFile $enigmaPath -UseBasicParsing
|
||||
Write-Host "✅ Enigma Virtual Box 下载成功"
|
||||
} catch {
|
||||
Write-Host "⚠️ 下载失败,使用备用方案"
|
||||
# 创建简单的自解压脚本作为备选
|
||||
$altScript = @"
|
||||
' 备选打包脚本 - 复制所有文件到输出目录
|
||||
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||
Set shell = CreateObject("WScript.Shell")
|
||||
|
||||
srcFolder = "build\windows\x64\runner\Release"
|
||||
destFolder = "dist\windows-package"
|
||||
|
||||
If fso.FolderExists(srcFolder) Then
|
||||
If Not fso.FolderExists(destFolder) Then
|
||||
fso.CreateFolder(destFolder)
|
||||
End If
|
||||
|
||||
' 复制所有文件
|
||||
Set folder = fso.GetFolder(srcFolder)
|
||||
For Each file In folder.Files
|
||||
file.Copy destFolder & "\" & file.Name, True
|
||||
Next
|
||||
|
||||
' 复制子文件夹
|
||||
For Each subFolder In folder.SubFolders
|
||||
fso.CopyFolder subFolder.Path, destFolder & "\" & subFolder.Name, True
|
||||
Next
|
||||
|
||||
WScript.Echo "✅ 文件打包完成"
|
||||
Else
|
||||
WScript.Echo "❌ 源文件夹不存在"
|
||||
End If
|
||||
"@
|
||||
|
||||
Set-Content -Path "C:\package.vbs" -Value $altScript
|
||||
}
|
||||
|
||||
- name: Package Single EXE
|
||||
shell: powershell
|
||||
run: |
|
||||
Write-Host "=== 开始打包单文件 EXE ==="
|
||||
|
||||
$buildPath = "build\windows\x64\runner\Release"
|
||||
$outputPath = "dist"
|
||||
$enigmaPath = "C:\enigmavb.exe"
|
||||
|
||||
# 创建输出目录
|
||||
if (-not (Test-Path $outputPath)) {
|
||||
New-Item -ItemType Directory -Path $outputPath -Force | Out-Null
|
||||
}
|
||||
|
||||
# 获取主程序
|
||||
$exeFile = Get-ChildItem -Path $buildPath -Filter "*.exe" | Select-Object -First 1
|
||||
if (-not $exeFile) {
|
||||
Write-Host "❌ 未找到可执行文件"
|
||||
exit 1
|
||||
}
|
||||
|
||||
$inputExe = $exeFile.FullName
|
||||
$outputExe = "$outputPath\$($exeFile.BaseName)_Single.exe"
|
||||
|
||||
Write-Host "主程序: $inputExe"
|
||||
Write-Host "输出: $outputExe"
|
||||
|
||||
# 尝试使用 Enigma Virtual Box
|
||||
if (Test-Path $enigmaPath) {
|
||||
Write-Host "使用 Enigma Virtual Box 打包..."
|
||||
|
||||
# 创建配置文件
|
||||
$configContent = @"
|
||||
[Config]
|
||||
InputFile=$inputExe
|
||||
OutputFile=$outputExe
|
||||
Files=%DEFAULT FOLDER%
|
||||
VirtualizationMode=Never Write To Disk
|
||||
Compression=Yes
|
||||
ShareVirtualSystem=Yes
|
||||
|
||||
[Files]
|
||||
Folder=$buildPath\*
|
||||
"@
|
||||
|
||||
$configFile = "$outputPath\package_config.evb"
|
||||
Set-Content -Path $configFile -Value $configContent
|
||||
|
||||
# 执行打包
|
||||
$process = Start-Process -FilePath $enigmaPath -ArgumentList "/sf", $inputExe, "/lf", $outputExe, "/folder", $buildPath, "/compress" -Wait -PassThru -NoNewWindow
|
||||
|
||||
if ($process.ExitCode -eq 0) {
|
||||
Write-Host "✅ 单文件打包成功!"
|
||||
|
||||
# 显示压缩信息
|
||||
$originalSize = (Get-Item $inputExe).Length / 1MB
|
||||
$packedSize = (Get-Item $outputExe).Length / 1MB
|
||||
Write-Host "原始大小: $([math]::Round($originalSize, 2)) MB"
|
||||
Write-Host "打包大小: $([math]::Round($packedSize, 2)) MB"
|
||||
} else {
|
||||
Write-Host "⚠️ Enigma 打包失败,使用备选方案"
|
||||
throw "Enigma failed"
|
||||
}
|
||||
} else {
|
||||
Write-Host "⚠️ Enigma 未找到,使用 7-Zip 自解压方案"
|
||||
throw "Enigma not found"
|
||||
}
|
||||
|
||||
- name: Package with 7-Zip Alternative
|
||||
if: failure()
|
||||
shell: powershell
|
||||
run: |
|
||||
Write-Host "使用 7-Zip 自解压方案..."
|
||||
|
||||
$buildPath = "build\windows\x64\runner\Release"
|
||||
$outputPath = "dist"
|
||||
|
||||
# 检查 7-Zip
|
||||
$7zipPath = "C:\Program Files\7-Zip\7z.exe"
|
||||
if (-not (Test-Path $7zipPath)) {
|
||||
Write-Host "安装 7-Zip..."
|
||||
choco install 7zip -y
|
||||
$7zipPath = "C:\Program Files\7-Zip\7z.exe"
|
||||
}
|
||||
|
||||
# 获取主程序名称
|
||||
$exeFile = Get-ChildItem -Path $buildPath -Filter "*.exe" | Select-Object -First 1
|
||||
$outputSfx = "$outputPath\$($exeFile.BaseName)_Package.exe"
|
||||
|
||||
Write-Host "创建自解压包..."
|
||||
|
||||
# 创建配置文件
|
||||
$configContent = @"
|
||||
;!@Install@!UTF-8!
|
||||
Title="HostExecutor Windows Package"
|
||||
BeginPrompt="正在解压 HostExecutor..."
|
||||
ExtractDialogText="请稍候,正在解压文件..."
|
||||
ExtractPathText="解压路径:"
|
||||
ExtractTitle="解压中"
|
||||
FinishMessage="解压完成!"
|
||||
GUIFlags="8"
|
||||
;!@InstallEnd@!
|
||||
"@
|
||||
|
||||
$configFile = "$outputPath\config.txt"
|
||||
Set-Content -Path $configFile -Value $configContent -Encoding UTF8
|
||||
|
||||
# 创建压缩包
|
||||
& $7zipPath a -sfx "$outputSfx" "$buildPath\*" -mmt=on -mx=9
|
||||
|
||||
if (Test-Path $outputSfx) {
|
||||
Write-Host "✅ 7-Zip 自解压包创建成功!"
|
||||
Write-Host "输出文件: $outputSfx"
|
||||
|
||||
$size = (Get-Item $outputSfx).Length / 1MB
|
||||
Write-Host "文件大小: $([math]::Round($size, 2)) MB"
|
||||
} else {
|
||||
Write-Host "❌ 7-Zip 打包失败"
|
||||
}
|
||||
|
||||
- name: Upload Single EXE Package
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: windows-single-exe
|
||||
path: dist/*.exe
|
||||
if: always()
|
||||
|
||||
Reference in New Issue
Block a user