Files
hw3/scripts/run-full-pipeline.ps1

97 lines
3.0 KiB
PowerShell

$ErrorActionPreference = "Stop"
function Invoke-Step {
param(
[Parameter(Mandatory = $true)][string]$Name,
[Parameter(Mandatory = $true)][string]$Command
)
Write-Host ""
Write-Host "=== $Name ===" -ForegroundColor Cyan
Write-Host $Command
Invoke-Expression $Command
if ($LASTEXITCODE -ne 0) {
throw "Step '$Name' failed with exit code $LASTEXITCODE"
}
}
function Start-DockerDesktopIfNeeded {
function Test-DockerDaemonReady {
cmd /c "docker info >nul 2>nul"
return ($LASTEXITCODE -eq 0)
}
$dockerInfoOk = Test-DockerDaemonReady
if ($dockerInfoOk) {
return
}
$candidatePaths = @(
"$Env:ProgramFiles\Docker\Docker\Docker Desktop.exe",
"$Env:ProgramFiles(x86)\Docker\Docker\Docker Desktop.exe"
)
$dockerExe = $candidatePaths | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $dockerExe) {
throw "Docker Desktop not found. Install Docker Desktop or start Docker manually."
}
# Try to start Docker Desktop even if process exists; daemon may be down.
Write-Host "Ensuring Docker Desktop is started..." -ForegroundColor Yellow
Start-Process -FilePath $dockerExe | Out-Null
# If the process still does not appear, fail fast.
$dockerProcess = Get-Process -Name "Docker Desktop" -ErrorAction SilentlyContinue
if (-not $dockerProcess) {
$dockerProcess = Get-Process -Name "Docker Desktop.exe" -ErrorAction SilentlyContinue
}
if (-not $dockerProcess) {
Write-Host "Docker Desktop process is not detected yet; waiting for daemon..." -ForegroundColor Yellow
}
$deadline = (Get-Date).AddMinutes(3)
while ((Get-Date) -lt $deadline) {
if (Test-DockerDaemonReady) {
return
}
Start-Sleep -Seconds 3
}
throw "Docker daemon is not available after 3 minutes."
}
function Wait-Selenoid {
param(
[Parameter(Mandatory = $true)][string]$StatusUrl
)
$deadline = (Get-Date).AddMinutes(2)
while ((Get-Date) -lt $deadline) {
try {
$response = Invoke-RestMethod -Uri $StatusUrl -Method Get -TimeoutSec 5
if ($null -ne $response.total -and $response.total -ge 1) {
return
}
} catch {
Start-Sleep -Seconds 2
continue
}
Start-Sleep -Seconds 2
}
throw "Selenoid is not ready at $StatusUrl"
}
Write-Host "Preparing Docker/Selenoid..." -ForegroundColor Green
Start-DockerDesktopIfNeeded
Invoke-Step -Name "Docker Compose Up" -Command "docker compose up -d --wait"
Wait-Selenoid -StatusUrl "http://localhost:4444/status"
Invoke-Step -Name "Quality Gates" -Command "mvn -DskipTests verify"
Invoke-Step -Name "API and Stub Tests" -Command "mvn test"
Invoke-Step -Name "UI Tests via Selenoid" -Command "mvn -Pui-tests ""-Dbrowser=selenoid"" ""-Dselenoid.url=http://localhost:4444/wd/hub"" test"
Write-Host ""
Write-Host "Full pipeline completed successfully." -ForegroundColor Green