Repair scratch setup preflight for repo-local host processes

This commit is contained in:
master
2026-03-11 21:19:25 +02:00
parent 4a84f901ab
commit 08006100a5
7 changed files with 221 additions and 6 deletions

View File

@@ -21,6 +21,7 @@
[CmdletBinding()]
param(
[switch]$Test,
[switch]$StopRepoHostProcesses,
[ValidateSet('Debug', 'Release')]
[string]$Configuration = 'Debug'
)
@@ -49,6 +50,103 @@ function Get-RepoRelativePath {
return $normalizedPath
}
function Test-RepoOwnedText {
param(
[Parameter(Mandatory = $true)]
[string]$Root,
[AllowNull()]
[string]$Value
)
if ([string]::IsNullOrWhiteSpace($Value)) {
return $false
}
$normalizedRoot = [System.IO.Path]::GetFullPath($Root).TrimEnd('\', '/')
$normalizedValue = $Value.Replace('/', '\')
return $normalizedValue.IndexOf($normalizedRoot, [System.StringComparison]::OrdinalIgnoreCase) -ge 0
}
function Test-IsWindowsPlatform {
return [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform(
[System.Runtime.InteropServices.OSPlatform]::Windows)
}
function Stop-RepoHostProcesses {
param(
[Parameter(Mandatory = $true)]
[string]$Root
)
if (-not (Test-IsWindowsPlatform)) {
return
}
$candidates = @(Get-CimInstance Win32_Process -Filter "Name = 'dotnet.exe' OR Name LIKE 'StellaOps.%'")
$staleProcesses = @()
foreach ($candidate in $candidates) {
if ($candidate.ProcessId -eq $PID) {
continue
}
$executablePath = "$($candidate.ExecutablePath)"
$commandLine = "$($candidate.CommandLine)"
$name = "$($candidate.Name)"
$repoOwned = (Test-RepoOwnedText -Root $Root -Value $executablePath) -or
(Test-RepoOwnedText -Root $Root -Value $commandLine)
if (-not $repoOwned) {
continue
}
$looksLikeService = $name -like 'StellaOps.*' -or $commandLine -match 'StellaOps\.[A-Za-z0-9_.-]+'
if (-not $looksLikeService) {
continue
}
$staleProcesses += [pscustomobject]@{
ProcessId = $candidate.ProcessId
Name = $name
ExecutablePath = $executablePath
CommandLine = $commandLine
}
}
$staleProcesses = @($staleProcesses | Sort-Object ProcessId -Unique)
if ($staleProcesses.Count -eq 0) {
Write-Host 'No repo-local Stella host processes detected.' -ForegroundColor DarkGray
return
}
Write-Host "Stopping $($staleProcesses.Count) repo-local Stella host process(es) before build." -ForegroundColor Yellow
foreach ($stale in $staleProcesses) {
$location = if (-not [string]::IsNullOrWhiteSpace($stale.ExecutablePath)) {
Get-RepoRelativePath -Root $Root -Path $stale.ExecutablePath
} else {
$stale.CommandLine
}
Write-Host " - [$($stale.ProcessId)] $($stale.Name) :: $location" -ForegroundColor DarkYellow
Stop-Process -Id $stale.ProcessId -Force -ErrorAction Stop
}
Start-Sleep -Seconds 1
$remaining = @($staleProcesses | Where-Object { Get-Process -Id $_.ProcessId -ErrorAction SilentlyContinue })
if ($remaining.Count -gt 0) {
$remainingIds = ($remaining | ForEach-Object { $_.ProcessId }) -join ', '
throw "Failed to stop repo-local Stella host processes: $remainingIds"
}
Write-Host 'Repo-local Stella host processes stopped.' -ForegroundColor Green
}
if ($StopRepoHostProcesses) {
Stop-RepoHostProcesses -Root $repoRoot
}
$solutions = Get-ChildItem -Path $srcDir -Filter '*.sln' -Recurse |
Where-Object {
$_.Name -ne 'StellaOps.sln' -and