Skip to content

Get-PrBuildIds.ps1 reports SUCCESS while build is still in progress #19312

@T-Gro

Description

@T-Gro

Bug

Get-PrBuildIds.ps1 can report State = SUCCESS for a build that is still running.

Root cause

The script calls gh pr checks which returns one row per job (e.g. 36 rows for fsharp-ci), all sharing the same buildId. It then deduplicates with Sort-Object -Property Pipeline, BuildId -Unique, which picks one arbitrary row. If that row happens to be a completed job (e.g. CheckCodeFormatting), the overall state shows SUCCESS even though 25 other jobs are still IN_PROGRESS.

File: .github/skills/pr-build-status/scripts/Get-PrBuildIds.ps1, final pipeline (~line 55):

} | Sort-Object -Property Pipeline, BuildId -Unique

Repro

  1. Open a PR that triggers fsharp-ci
  2. Wait until the Build stage finishes but test stages are still running
  3. Run: pwsh .github/skills/pr-build-status/scripts/Get-PrBuildIds.ps1 -PrNumber <PR>
  4. Observe State = SUCCESS even though Get-BuildInfo.ps1 -BuildId <id> shows Status = inProgress

Observed on PR #19309, build 1297255: script said SUCCESS, actual state was 10/36 SUCCESS + 25 IN_PROGRESS + 1 QUEUED.

Suggested fix

Replace the Sort-Object -Unique with a Group-Object BuildId and derive worst-case state per build:

$builds = $checks | Where-Object { $_.link -match "dev\.azure\.com" } | ForEach-Object {
    $buildId = if ($_.link -match "buildId=(\d+)") { $matches[1] } else { $null }
    $pipeline = ($_.name -split " ")[0]
    [PSCustomObject]@{
        Pipeline = $pipeline
        BuildId  = $buildId
        State    = $_.state
        Link     = $_.link
    }
} | Group-Object BuildId | ForEach-Object {
    $jobs = $_.Group
    $states = $jobs | Select-Object -ExpandProperty State -Unique
    $overall = if ($states -contains "FAILURE") { "FAILURE" }
               elseif ($states -contains "IN_PROGRESS" -or $states -contains "QUEUED") { "IN_PROGRESS" }
               else { "SUCCESS" }
    $first = $jobs | Select-Object -First 1
    [PSCustomObject]@{
        Pipeline = $first.Pipeline
        BuildId  = $first.BuildId
        State    = $overall
        Detail   = ($jobs | Group-Object State | ForEach-Object { "$($_.Count) $($_.Name)" }) -join ", "
        Link     = ($first.Link -replace "\&view=.*", "")
    }
}

This also trims the job-specific &view=logs&jobId=... suffix from the link so it points to the build overview.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

New

Relationships

None yet

Development

No branches or pull requests

Issue actions