chore: 优化多平台打包

This commit is contained in:
Luke 2025-08-27 15:24:58 +08:00
parent eb7e2e7e93
commit 44b2ebb64a
2 changed files with 83 additions and 2 deletions

View File

@ -49,6 +49,87 @@ $targetDir = Join-Path $projectRoot "target\release"
$outDir = Join-Path $targetDir "Snow-v$version-linux-x64" $outDir = Join-Path $targetDir "Snow-v$version-linux-x64"
$tgzPath = Join-Path $targetDir "Snow-v$version-linux-x64.tgz" $tgzPath = Join-Path $targetDir "Snow-v$version-linux-x64.tgz"
# ===== Step 5: Package to .tgz (no extra top-level dir, max compression) =====
Write-Host "Step 5: Package to .tgz..."
if (-not (Test-Path -LiteralPath $outDir)) {
Write-Error "Output directory not found: $outDir"
exit 1
}
# Ensure target directory exists
if (-not (Test-Path -LiteralPath $targetDir)) {
New-Item -ItemType Directory -Force -Path $targetDir | Out-Null
}
# Remove old package if exists
if (Test-Path -LiteralPath $tgzPath) {
Write-Host "→ Removing existing tgz: $tgzPath"
Remove-Item -LiteralPath $tgzPath -Force
}
function Invoke-TarGz {
param(
[Parameter(Mandatory = $true)][string]$SourceDir,
[Parameter(Mandatory = $true)][string]$DestTgz
)
$tarExe = "tar"
$isWindows = $env:OS -eq 'Windows_NT'
if ($isWindows) {
$psi = @{
FilePath = $tarExe
ArgumentList= @("-C", $SourceDir, "-czf", $DestTgz, ".")
NoNewWindow = $true
Wait = $true
}
try {
$p = Start-Process @psi -PassThru -ErrorAction Stop
$p.WaitForExit()
if ($p.ExitCode -ne 0) {
throw "tar exited with code $($p.ExitCode)"
}
} catch {
throw "Packaging failed (Windows tar): $($_.Exception.Message)"
}
} else {
try {
$psi = @{
FilePath = $tarExe
ArgumentList= @("-C", $SourceDir, "-c", "-f", $DestTgz, "-I", "gzip -9", ".")
NoNewWindow = $true
Wait = $true
}
$p = Start-Process @psi -PassThru -ErrorAction Stop
$p.WaitForExit()
if ($p.ExitCode -eq 0) { return }
} catch { }
try {
$psi = @{
FilePath = $tarExe
ArgumentList= @("-C", $SourceDir, "-c", "-z", "-f", $DestTgz, ".")
NoNewWindow = $true
Wait = $true
}
$p = Start-Process @psi -PassThru -ErrorAction Stop
$p.WaitForExit()
if ($p.ExitCode -ne 0) {
throw "tar exited with code $($p.ExitCode)"
}
} catch {
throw "Packaging failed (Linux tar): $($_.Exception.Message)"
}
}
}
try {
Invoke-TarGz -SourceDir $outDir -DestTgz $tgzPath
} catch {
Write-Error $_.Exception.Message
exit 1
}
Write-Host ">>> Package ready!" -ForegroundColor Green Write-Host ">>> Package ready!" -ForegroundColor Green
Write-Host "Version : $version" Write-Host "Version : $version"
Write-Host "Output Dir : $outDir" Write-Host "Output Dir : $outDir"

View File

@ -91,7 +91,7 @@ try {
Write-Host ">>> lib directory not found, skipping." -ForegroundColor Yellow Write-Host ">>> lib directory not found, skipping." -ForegroundColor Yellow
} }
# ===== Step 4: Create zip ===== # ===== Step 4: Create release zip =====
Write-Host "Step 4: Create release zip..." Write-Host "Step 4: Create release zip..."
New-Item -ItemType Directory -Force -Path $releaseRoot | Out-Null New-Item -ItemType Directory -Force -Path $releaseRoot | Out-Null
$zipPath = Join-Path $releaseRoot ("{0}.zip" -f $verName) $zipPath = Join-Path $releaseRoot ("{0}.zip" -f $verName)
@ -101,7 +101,7 @@ try {
} }
try { try {
Compress-Archive -Path $outDir -DestinationPath $zipPath -Force Compress-Archive -Path (Join-Path $outDir '*') -DestinationPath $zipPath -CompressionLevel Optimal -Force
} catch { } catch {
Write-Error "Failed to create zip: $($_.Exception.Message)" Write-Error "Failed to create zip: $($_.Exception.Message)"
exit 1 exit 1