Files
shop-server/scripts/deploy-ssh.ps1
T
@kirill.komarov e67d8bdc0a deploy
2026-05-10 16:49:55 +05:00

80 lines
2.7 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Вызывает deploy-ssh.sh через bash (Git for Windows или bash в PATH).
# Запускайте из корня репозитория или откуда угодно — скрипт перейдёт в root.
param(
[switch]$FrontendOnly,
[switch]$BackendOnly,
[switch]$All,
[switch]$DryRun,
[switch]$SkipBuild,
[switch]$Help
)
$ErrorActionPreference = "Stop"
$scriptsDir = $PSScriptRoot
$repoRoot = (Resolve-Path (Join-Path $scriptsDir "..")).Path
$gitUsrRs = "C:\Program Files\Git\usr\bin\rsync.exe"
$chocoRsDir = "C:\ProgramData\chocolatey\bin"
$chocoRs = Join-Path $chocoRsDir "rsync.exe"
if (Test-Path -LiteralPath $gitUsrRs) {
$env:Path = "C:\Program Files\Git\usr\bin;$env:Path"
} elseif (Test-Path -LiteralPath $chocoRs) {
$env:Path = "$chocoRsDir;$env:Path"
}
function Show-Help {
@"
Использование (рядом с репозиторием или из любого каталога):
.\scripts\deploy-ssh.ps1 [-FrontendOnly] [-BackendOnly] [-All]
.\scripts\deploy-ssh.ps1 -DryRun -BackendOnly
Конфиг: scripts/deploy.env (скопируйте из deploy.env.example).
Нужны: bash (Git for Windows) и rsync в PATH. rsync без Git: установите пакет (например, choco install rsync).
"@ | Write-Host
}
if ($Help) { Show-Help; exit 0 }
$bash = Get-Command bash -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
if (-not $bash) {
$git = "C:\Program Files\Git\bin\bash.exe"
if (Test-Path $git) { $bash = $git }
}
if (-not $bash) {
Write-Error "Не найден bash. Установите Git for Windows и добавьте Git\usr\bin в PATH (rsync)."
}
if (-not (Get-Command rsync -ErrorAction SilentlyContinue)) {
Write-Error "Не найден rsync. Установите: choco install rsync -y либо добавьте C:\Program Files\Git\usr\bin в PATH."
}
$argsToSh = [System.Collections.ArrayList]@()
if ($FrontendOnly) { [void]$argsToSh.Add("--frontend-only") }
elseif ($BackendOnly) { [void]$argsToSh.Add("--backend-only") }
else { [void]$argsToSh.Add("--all") }
if ($DryRun) { [void]$argsToSh.Add("--dry-run") }
if ($SkipBuild) { [void]$argsToSh.Add("--skip-build") }
function ConvertTo-MsysPath {
param([string]$Path)
$full = if (Test-Path $Path) { (Resolve-Path -LiteralPath $Path).Path } else { $Path }
if ($full -match '^([A-Za-z]):[\\/](.*)$') {
return "/" + $Matches[1].ToLower() + "/" + ($Matches[2] -replace '\\', '/')
}
return ($full -replace '\\', '/')
}
$sh = Join-Path $scriptsDir "deploy-ssh.sh"
$shUnix = ConvertTo-MsysPath $sh
Push-Location $repoRoot
try {
& $bash $shUnix @argsToSh
exit $LASTEXITCODE
}
finally {
Pop-Location
}