run_lobster_travel_validation_ci.ps1 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # One-click CI/local gate: build fs-saas-company, restart, run travel full validation.
  2. # Usage:
  3. # cd d:\ylrz_saas_new\java\scripts
  4. # .\run_lobster_travel_validation_ci.ps1 -CompanyId 338 -TenantId 33
  5. # .\run_lobster_travel_validation_ci.ps1 -SkipBuild -SkipRestart
  6. param(
  7. [string]$ApiBase = "http://127.0.0.1:8006",
  8. [int]$CompanyId = 338,
  9. [int]$TenantId = 33,
  10. [string]$OpsSecret = "lobster-dev-ops",
  11. [string]$JavaHome = "",
  12. [switch]$SkipBuild,
  13. [switch]$SkipRestart,
  14. [switch]$SkipStress
  15. )
  16. $ErrorActionPreference = "Stop"
  17. $repoRoot = Split-Path $PSScriptRoot -Parent
  18. $jarPath = Join-Path $repoRoot "fs-saas-company\target\fs-saas-company.jar"
  19. $logPath = Join-Path $repoRoot "fs-saas-company-travel-validation-run.log"
  20. if ([string]::IsNullOrWhiteSpace($JavaHome)) {
  21. if ($env:JAVA_HOME) { $JavaHome = $env:JAVA_HOME }
  22. elseif (Test-Path "D:\jdk-17.0.2") { $JavaHome = "D:\jdk-17.0.2" }
  23. else { throw "Set -JavaHome or JAVA_HOME" }
  24. }
  25. $mvn = "D:\maven\apache-maven-3.9.15\bin\mvn.cmd"
  26. if (-not (Test-Path $mvn)) {
  27. $mvn = "mvn"
  28. }
  29. Write-Host "=== Lobster Travel Validation CI ===" -ForegroundColor Cyan
  30. if (-not $SkipBuild) {
  31. Write-Host "[1/3] mvn package fs-saas-company ..." -ForegroundColor Yellow
  32. $env:JAVA_HOME = $JavaHome
  33. $env:PATH = "$JavaHome\bin;$env:PATH"
  34. Push-Location $repoRoot
  35. & $mvn -pl fs-saas-company -am package -DskipTests -q
  36. if ($LASTEXITCODE -ne 0) { throw "Maven build failed" }
  37. Pop-Location
  38. } else {
  39. Write-Host "[1/3] skip build" -ForegroundColor DarkGray
  40. }
  41. if (-not $SkipRestart) {
  42. Write-Host "[2/3] restart fs-saas-company :8006 ..." -ForegroundColor Yellow
  43. Get-NetTCPConnection -LocalPort 8006 -ErrorAction SilentlyContinue |
  44. ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }
  45. Start-Sleep -Seconds 2
  46. if (-not (Test-Path $jarPath)) { throw "Jar missing: $jarPath" }
  47. Start-Process -FilePath "$JavaHome\bin\java.exe" `
  48. -ArgumentList @("-jar", $jarPath, "--spring.profiles.active=dev") `
  49. -RedirectStandardOutput $logPath `
  50. -RedirectStandardError "${logPath}.err" `
  51. -WindowStyle Hidden
  52. $deadline = (Get-Date).AddMinutes(5)
  53. $ready = $false
  54. do {
  55. Start-Sleep -Seconds 3
  56. try {
  57. $pingHeaders = @{ "X-Lobster-Ops-Secret" = $OpsSecret }
  58. Invoke-RestMethod -Uri "$ApiBase/api/lobster/admin/phase2/verify/$CompanyId?tenantId=$TenantId" `
  59. -Headers $pingHeaders -TimeoutSec 8 | Out-Null
  60. $ready = $true
  61. break
  62. } catch {
  63. if ((Get-Date) -gt $deadline) { break }
  64. }
  65. } while ((Get-Date) -lt $deadline)
  66. if (-not $ready) { throw "Service not ready on $ApiBase (see $logPath)" }
  67. Write-Host " service is up" -ForegroundColor Green
  68. } else {
  69. Write-Host "[2/3] skip restart" -ForegroundColor DarkGray
  70. }
  71. Write-Host "[3/3] run lobster_travel_full_validation.ps1 ..." -ForegroundColor Yellow
  72. $valArgs = @{
  73. ApiBase = $ApiBase
  74. CompanyId = $CompanyId
  75. TenantId = $TenantId
  76. OpsSecret = $OpsSecret
  77. }
  78. if ($SkipStress) { $valArgs.SkipStress = $true }
  79. & (Join-Path $PSScriptRoot "lobster_travel_full_validation.ps1") @valArgs
  80. exit $LASTEXITCODE