LifePlay-Revival/Tools/RunCommandlet.ps1

64 lines
3 KiB
PowerShell
Raw Normal View History

<#
.SYNOPSIS
Lance une commandlet Unreal sur le projet 5.5 et archive son journal.
.DESCRIPTION
Journal complet : Saved\Logs\portage\<Lot>_<Commandlet>_<horodatage>.log
Resume (lignes Error/Warning dedoublonnees, lignes de la commandlet) :
Docs\Migration\etat\<Lot>_<Commandlet>_<horodatage>.txt
Retourne le code de sortie de la commandlet.
.EXAMPLE
.\Tools\RunCommandlet.ps1 -Lot L1 -Commandlet CompileAllBlueprints
.\Tools\RunCommandlet.ps1 -Lot L4 -Commandlet LPFixAssetRegistryPins -Args '-DryRun'
#>
param(
[Parameter(Mandatory)][string]$Lot,
[Parameter(Mandatory)][string]$Commandlet,
[string]$Args = '',
[string]$ProjectRoot = (Split-Path $PSScriptRoot -Parent),
[string]$Engine = 'D:\Game\Launcher\Engine\UE_5.5\Engine'
)
$ErrorActionPreference = 'Stop'
$cmd = Join-Path $Engine 'Binaries\Win64\UnrealEditor-Cmd.exe'
$proj = Join-Path $ProjectRoot 'LifePlay.uproject'
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$name = "${Lot}_${Commandlet}_$stamp"
$log = Join-Path $ProjectRoot "Saved\Logs\portage\$name.log"
$sum = Join-Path $ProjectRoot "Docs\Migration\etat\$name.txt"
New-Item -ItemType Directory -Force (Split-Path $log -Parent), (Split-Path $sum -Parent) | Out-Null
$argLine = "`"$proj`" -run=$Commandlet $Args -unattended -nopause -nosplash -stdout -FullStdOutLogOutput -abslog=`"$log`""
Write-Host "> $cmd $argLine"
$t0 = Get-Date
$p = Start-Process -FilePath $cmd -ArgumentList $argLine -NoNewWindow -PassThru -Wait -RedirectStandardOutput "$log.stdout"
$dur = [int]((Get-Date) - $t0).TotalSeconds
Remove-Item "$log.stdout" -ErrorAction SilentlyContinue
$lines = if (Test-Path $log) { Get-Content $log } else { @() }
# Retire horodatage et numero de trame pour dedoublonner
$strip = { param($l) $l -replace '^\[[^\]]+\]\[\s*\d+\]', '' }
$errs = $lines | Where-Object { $_ -match ': Error: |: Fatal' } | ForEach-Object { & $strip $_ } | Group-Object | Sort-Object Count -Descending
$warns = $lines | Where-Object { $_ -match ': Warning: ' } | ForEach-Object { & $strip $_ } | Group-Object | Sort-Object Count -Descending
$own = $lines | Where-Object { $_ -match 'LogLP|LogCompileAllBlueprints|CompileAllBlueprints|Success -|Failure -|Blueprints? (compiled|failed)' } | ForEach-Object { & $strip $_ }
@(
"Commandlet : $Commandlet $Args"
"Lot : $Lot"
"Date : $(Get-Date -Format s) duree : $dur s code de sortie : $($p.ExitCode)"
"Journal : $log"
""
"=== Erreurs : $(($errs | Measure-Object Count -Sum).Sum) lignes, $(@($errs).Count) signatures"
$errs | ForEach-Object { '{0,6} {1}' -f $_.Count, $_.Name }
""
"=== Avertissements : $(($warns | Measure-Object Count -Sum).Sum) lignes, $(@($warns).Count) signatures (100 premieres)"
$warns | Select-Object -First 100 | ForEach-Object { '{0,6} {1}' -f $_.Count, $_.Name }
""
"=== Sortie de la commandlet"
$own
) | Set-Content $sum -Encoding UTF8
Write-Host "code=$($p.ExitCode) duree=${dur}s erreurs=$(($errs | Measure-Object Count -Sum).Sum) avertissements=$(($warns | Measure-Object Count -Sum).Sum)"
Write-Host "resume : $sum"
exit $p.ExitCode