From d8eb7db1e1a14098e08913f31adf3b864ab962c3 Mon Sep 17 00:00:00 2001 From: WuYongJie Date: Tue, 10 Mar 2026 18:36:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8F=91=E5=B8=83=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/publish-to-server.ps1 | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/publish-to-server.ps1 b/scripts/publish-to-server.ps1 index a2ccc14..1505193 100644 --- a/scripts/publish-to-server.ps1 +++ b/scripts/publish-to-server.ps1 @@ -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"