157 lines
6.6 KiB
PowerShell
157 lines
6.6 KiB
PowerShell
# --- CONFIGURAZIONE ---
|
|
$pattern = "IOB-WIN-*.sln"
|
|
$sharedProjectPath = ".\IOB-WIN-FORM\IOB-WIN-FORM.csproj"
|
|
|
|
# Controllo robusto del parametro --agent (cerca in tutti gli argomenti passati)
|
|
$agentMode = $args -contains "--agent"
|
|
|
|
# Avvia il cronometro per calcolare il tempo totale
|
|
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
|
|
|
|
# 1. Trova l'MSBuild ufficiale di Visual Studio 2022
|
|
$vsPaths = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -version "[17.0,18.0)" -products * -requires Microsoft.Component.MSBuild -property installationPath
|
|
if (-not $vsPaths) {
|
|
if ($agentMode) { exit 1 }
|
|
Write-Host "❌ Impossibile trovare Visual Studio 2022!" -ForegroundColor Red
|
|
Exit
|
|
}
|
|
$msbuildPath = Join-Path $vsPaths[0] "MSBuild\Current\Bin\MSBuild.exe"
|
|
|
|
if (-not $agentMode) {
|
|
Write-Host "🎯 Usando MSBuild di VS2022: $msbuildPath" -ForegroundColor Gray
|
|
}
|
|
|
|
# Cerca tutte le soluzioni escludendo cartelle di build
|
|
$solutions = Get-ChildItem -Path . -Filter $pattern -Recurse | Where-Object {
|
|
$_.FullName -notmatch '\\(bin|obj|\\.git|\\.vs)\\.'
|
|
}
|
|
|
|
if ($solutions.Count -eq 0) {
|
|
if ($agentMode) { exit 1 }
|
|
Write-Host "⚠️ Nessuna soluzione trovata che corrisponde al pattern: $pattern" -ForegroundColor Yellow
|
|
Exit
|
|
}
|
|
|
|
if (-not $agentMode) {
|
|
Write-Host "🚀 Trovate $($solutions.Count) soluzioni univoche." -ForegroundColor Magenta
|
|
}
|
|
|
|
# FASE 1: Compilazione preventiva del progetto comune
|
|
if (Test-Path $sharedProjectPath) {
|
|
if (-not $agentMode) { Write-Host "`n📦 Fase 1: Compilazione del progetto comune condiviso..." -ForegroundColor Cyan }
|
|
|
|
# AGGIORNAMENTO: Se siamo in agentMode silenziamo completamente MSBuild (/v:q) e ridirigiamo l'output
|
|
if ($agentMode) {
|
|
& $msbuildPath $sharedProjectPath /p:Configuration=Release /v:q /nologo > $null 2>&1
|
|
}
|
|
else {
|
|
& $msbuildPath $sharedProjectPath /p:Configuration=Release /v:m /nologo
|
|
}
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
if (-not $agentMode) { Write-Host "❌ Errore critico: Impossibile compilare il progetto comune. Interruzione." -ForegroundColor Red }
|
|
exit 1
|
|
}
|
|
if (-not $agentMode) { Write-Host "✅ Progetto comune pronto." -ForegroundColor Green }
|
|
}
|
|
|
|
# FASE 2: Compilazione parallela iniziale
|
|
if (-not $agentMode) {
|
|
Write-Host "`n🛠️ Fase 2: Avvio compilazione parallela delle soluzioni (Max 4)..." -ForegroundColor Magenta
|
|
Write-Host "==================================================" -ForegroundColor Magenta
|
|
}
|
|
|
|
$parallelResults = $solutions | ForEach-Object -Parallel {
|
|
$solName = $_.Name
|
|
$solPath = $_.FullName
|
|
$msb = $using:msbuildPath
|
|
|
|
# Aggiunto /nologo per evitare intestazioni ripetute nei log interni
|
|
$log = & $msb $solPath /p:Configuration=Release /m:1 /p:BuildInParallel=false /v:m /nologo 2>&1
|
|
|
|
[PSCustomObject]@{
|
|
Name = $solName
|
|
FullName = $solPath
|
|
Success = ($LASTEXITCODE -eq 0)
|
|
Log = $log
|
|
}
|
|
} -ThrottleLimit 4
|
|
|
|
# --- ANALISI PRIMO ROUND E FASE 3 (RETRY SEQUENZIALE) ---
|
|
$successSolutions = @()
|
|
$failedToRetry = @()
|
|
|
|
foreach ($res in $parallelResults) {
|
|
if ($res.Success) {
|
|
if (-not $agentMode) { Write-Host "✅ $($res.Name) compilata con successo (in parallelo)!" -ForegroundColor Green }
|
|
$successSolutions += $res.Name
|
|
}
|
|
else {
|
|
if (-not $agentMode) { Write-Host "⚠️ $($res.Name) fallita in parallelo. Accodata per il recupero sequenziale..." -ForegroundColor Yellow }
|
|
$failedToRetry += $res
|
|
}
|
|
}
|
|
|
|
# Se ci sono falliti, li rieseguiamo UNO ALLA VOLTA pulendo la cache
|
|
if ($failedToRetry.Count -gt 0) {
|
|
if (-not $agentMode) {
|
|
Write-Host "`n🔄 Fase 3: Riesecuzione sequenziale dei task falliti ($($failedToRetry.Count) soluzioni)..." -ForegroundColor Magenta
|
|
Write-Host "==================================================" -ForegroundColor Magenta
|
|
}
|
|
|
|
foreach ($failedRes in $failedToRetry) {
|
|
if (-not $agentMode) { Write-Host "⏳ Ripristino e compilazione sequenziale: $($failedRes.Name)..." -ForegroundColor Cyan }
|
|
|
|
& $msbuildPath $failedRes.FullName /t:Restore /v:q /nologo > $null 2>&1
|
|
& $msbuildPath $failedRes.FullName /t:Clean /v:q /p:Configuration=Release /nologo > $null 2>&1
|
|
$retryLog = & $msbuildPath $failedRes.FullName /t:Build /p:Configuration=Release /v:m /nologo 2>&1
|
|
|
|
if ($LASTEXITCODE -eq 0) {
|
|
if (-not $agentMode) { Write-Host "✅ FALSO ALLARME: $($failedRes.Name) compilata correttamente in sequenziale!" -ForegroundColor Green }
|
|
$successSolutions += $failedRes.Name
|
|
}
|
|
else {
|
|
if (-not $agentMode) { Write-Host "❌ ERRORE REALE: $($failedRes.Name) è fallita anche in sequenziale." -ForegroundColor Red }
|
|
$failedRes.Log = $retryLog
|
|
}
|
|
}
|
|
}
|
|
|
|
# Ferma il cronometro e calcola il tempo trascorso
|
|
$stopwatch.Stop()
|
|
$elapsedTime = "{0:mm\:ss}" -f $stopwatch.Elapsed
|
|
|
|
# --- ELABORAZIONE DEI RISULTATI FINALI ---
|
|
$totalCount = $solutions.Count
|
|
$successCount = $successSolutions.Count
|
|
$failCount = $totalCount - $successCount
|
|
$failColor = if ($failCount -gt 0) { "Red" } else { "Gray" }
|
|
|
|
# --- RIEPILOGO FINALE ---
|
|
if (-not $agentMode) {
|
|
Write-Host "`n==================================================" -ForegroundColor Magenta
|
|
Write-Host "🏁 Processo di verifica completato in $elapsedTime!" -ForegroundColor Magenta
|
|
Write-Host "==================================================" -ForegroundColor Magenta
|
|
Write-Host " Soluzioni Totali: $totalCount" -ForegroundColor White
|
|
Write-Host " Successi totali: $successCount" -ForegroundColor Green
|
|
Write-Host " Errori reali: $failCount" -ForegroundColor $failColor
|
|
Write-Host " Tempo impiegato: $elapsedTime" -ForegroundColor Cyan
|
|
|
|
if ($failCount -gt 0) {
|
|
Write-Host "`n❌ Elenco delle soluzioni con ERRORI REALI:" -ForegroundColor Red
|
|
foreach ($res in $parallelResults) {
|
|
if ($successSolutions -notcontains $res.Name) {
|
|
Write-Host " - $($res.Name)" -ForegroundColor Red
|
|
Write-Host " 👉 Ultimi dettagli errore:" -ForegroundColor DarkRed
|
|
$res.Log | Where-Object { $_ -match "error" } | Select-Object -First 3 | Write-Host -ForegroundColor Gray
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "`n🎉 Eccellente! Tutte le soluzioni compilano senza errori." -ForegroundColor Green
|
|
}
|
|
Write-Host "==================================================" -ForegroundColor Magenta
|
|
}
|
|
|
|
# Exit code standard per ambienti automatizzati (0 = Successo, 1 = Fallimento)
|
|
if ($failCount -gt 0) { exit 1 } else { exit 0 } |