Public/Test-CCReleaseOutcome.ps1

function Test-CCReleaseOutcome {
    <#
    .SYNOPSIS
        Asks every place a release was meant to reach whether it got there, one row per target. Changes nothing.
    .DESCRIPTION
        A tag that passed the release gate and a workflow that went green do not say that a release
        happened. A release has happened when the version is where a consumer looks for it.

        A repository declares what its release publishes in .codecompass/config.yml:

          release:
            targets:
              - kind: nuget
                package: Tool.Core
              - kind: psgallery
                package: Tool
              - kind: github-release

        This asks each of them about one version, the latest tag's unless -Version is given:

          release.targets What a release publishes, as declared. A Warning when nothing is declared,
                              Skipped when the repository has never been tagged.
          release.published One row per target. Pass: the version is there. Fail: the target answered,
                              and the version is not there. Warning: the target could not be asked, or
                              the declaration is not one CodeCompass can ask about.

        Not knowing is not the same as absent, and neither is a pass. The release reached everything
        when every row is Pass.

        The feeds are read over HTTP without credentials: they are public. The GitHub Release is asked
        of the gh on the PATH, in the repository, so a private repository answers with the login a
        person already has.

        A feed lists a version some minutes after it is pushed. -WaitSeconds asks again until no row is
        Fail or the time is up, and then reports what it last heard.
    .PARAMETER Version
        The version to ask about, as 1.2.3 or v1.2.3. Default: the latest version tag reachable from HEAD.
    .PARAMETER WaitSeconds
        Keep asking for this long while a target answers that the version is not there. Default: ask once.
    .EXAMPLE
        Test-CCReleaseOutcome
    .EXAMPLE
        Publish-CCRelease -Part Minor; Test-CCReleaseOutcome -WaitSeconds 900
    .EXAMPLE
        Test-CCReleaseOutcome -Path . -Version 1.2.0 | Where-Object Status -NE 'Pass'
    #>

    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param(
        [Parameter(Position = 0)]
        [string]$Path = '.',

        [string]$Version,

        [ValidateRange(0, 7200)]
        [int]$WaitSeconds = 0
    )

    $full = (Resolve-Path -LiteralPath $Path).Path
    $asked = $null
    if ($Version) {
        $number = $Version -replace '^v', ''
        try { $asked = [CodeCompass.Core.Versioning.SemanticVersion]::Parse($number) }
        catch { throw "'$Version' is not a version. Give it as 1.2.3 or v1.2.3." }
    }

    $outcome = New-CCReleaseOutcome
    $deadline = (Get-Date).AddSeconds($WaitSeconds)
    while ($true) {
        $results = @($outcome.Check($full, $asked))
        $absent = @($results | Where-Object { "$($_.Status)" -eq 'Fail' })
        $left = ($deadline - (Get-Date)).TotalSeconds
        if ($absent.Count -eq 0 -or $left -le 0) { break }
        Write-Verbose "Not there yet: $(($absent | ForEach-Object { $_.Item }) -join ', '). Asking again, $([int]$left)s left."
        Start-Sleep -Seconds ([int][Math]::Max(1, [Math]::Min(20, $left)))
    }

    $results | ConvertTo-CCCheckRow
}