修复发布脚本兼容性问题
This commit is contained in:
parent
c0ce7a6e3e
commit
d8eb7db1e1
@ -18,7 +18,7 @@ $fileListPath = Join-Path ([System.IO.Path]::GetTempPath()) "equipment-managemen
|
||||
function Get-CommandPath([string]$name) {
|
||||
$cmd = Get-Command $name -ErrorAction SilentlyContinue
|
||||
if (-not $cmd) {
|
||||
throw "未找到命令: $name"
|
||||
throw "Command not found: $name"
|
||||
}
|
||||
return $cmd.Source
|
||||
}
|
||||
@ -32,7 +32,7 @@ function Invoke-External {
|
||||
|
||||
& $FilePath @Arguments
|
||||
if (-not $IgnoreExitCode -and $LASTEXITCODE -ne 0) {
|
||||
throw "命令执行失败: $FilePath $($Arguments -join ' ')"
|
||||
throw "Command failed: $FilePath $($Arguments -join ' ')"
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ Set-Location $projectRoot
|
||||
|
||||
$files = git ls-files --cached --others --exclude-standard
|
||||
if (-not $files) {
|
||||
throw "未找到可发布文件。"
|
||||
throw "No files to publish."
|
||||
}
|
||||
|
||||
$files | Set-Content -Path $fileListPath -Encoding utf8
|
||||
@ -58,7 +58,7 @@ if (Test-Path $archivePath) {
|
||||
Remove-Item $archivePath -Force
|
||||
}
|
||||
|
||||
Write-Host ">>> 打包当前仓库源码..."
|
||||
Write-Host ">>> Packing repository files..."
|
||||
Invoke-External -FilePath $tarExe -Arguments @("-czf", $archivePath, "-T", $fileListPath)
|
||||
|
||||
$remoteTarget = "$User@$HostName"
|
||||
@ -66,11 +66,13 @@ $sshBaseArgs = @("-o", "StrictHostKeyChecking=no")
|
||||
$scpBaseArgs = @("-o", "StrictHostKeyChecking=no")
|
||||
|
||||
if ($password) {
|
||||
Write-Host ">>> 使用 DEPLOY_PASSWORD 进行上传和远程执行..."
|
||||
Invoke-External -FilePath $sshpassExe -Arguments @("-p", $password, $scpExe) + $scpBaseArgs + @($archivePath, "${remoteTarget}:$RemoteArchive")
|
||||
Write-Host ">>> Using DEPLOY_PASSWORD for upload and remote execution..."
|
||||
$scpArgs = @("-p", $password, $scpExe) + $scpBaseArgs + @($archivePath, "${remoteTarget}:$RemoteArchive")
|
||||
Invoke-External -FilePath $sshpassExe -Arguments $scpArgs
|
||||
} else {
|
||||
Write-Host ">>> 使用 SSH 密钥或交互密码进行上传和远程执行..."
|
||||
Invoke-External -FilePath $scpExe -Arguments $scpBaseArgs + @($archivePath, "${remoteTarget}:$RemoteArchive")
|
||||
Write-Host ">>> Using SSH key or interactive password..."
|
||||
$scpArgs = $scpBaseArgs + @($archivePath, "${remoteTarget}:$RemoteArchive")
|
||||
Invoke-External -FilePath $scpExe -Arguments $scpArgs
|
||||
}
|
||||
|
||||
$skipBackupValue = if ($SkipBackup) { "1" } else { "0" }
|
||||
@ -95,9 +97,11 @@ rm -f '$RemoteArchive'
|
||||
"@
|
||||
|
||||
if ($password) {
|
||||
Invoke-External -FilePath $sshpassExe -Arguments @("-p", $password, $sshExe) + $sshBaseArgs + @($remoteTarget, $deployCommand)
|
||||
$sshArgs = @("-p", $password, $sshExe) + $sshBaseArgs + @($remoteTarget, $deployCommand)
|
||||
Invoke-External -FilePath $sshpassExe -Arguments $sshArgs
|
||||
} else {
|
||||
Invoke-External -FilePath $sshExe -Arguments $sshBaseArgs + @($remoteTarget, $deployCommand)
|
||||
$sshArgs = $sshBaseArgs + @($remoteTarget, $deployCommand)
|
||||
Invoke-External -FilePath $sshExe -Arguments $sshArgs
|
||||
}
|
||||
|
||||
Write-Host ">>> 发布流程完成"
|
||||
Write-Host ">>> Publish completed"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user