Last active
April 18, 2022 15:12
-
-
Save jedieaston/ec9da3062fcc40c2b3cd857309f2c91e to your computer and use it in GitHub Desktop.
A easy way to see if your winget-pkgs pipeline run is done!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given the PR number, see what the status of the pipeline is. | |
Param( | |
[Parameter(Position = 0, HelpMessage = "The Pull Request to check on.", Mandatory = $true)] | |
[String] $PullRequest | |
) | |
$ErrorActionPreference = "Stop" | |
$ProgressPreference = "SilentlyContinue" | |
$url = "https://dev.azure.com/ms/winget-pkgs/_apis/build/builds?branchName=refs/pull/$PullRequest/merge&api-version=6.0" | |
$result = Invoke-RestMethod $url | |
if ($result.count -eq 0) { | |
Write-Host "No runs found for PR" $PullRequest -ForegroundColor Yellow | |
exit | |
} | |
$lastRun = $result.value[0] | |
Write-Host "There have been" $result.count 'runs for PR' ('"' + $lastRun.triggerInfo.{pr.title} + '".') | |
if ($lastRun.status -ne "Completed") { | |
Write-Host "The last pipeline run is currently in-progress." -ForegroundColor Yellow | |
} | |
else { | |
$elapsedTime = ([datetime]::Parse($lastRun.finishTime) - [datetime]::Parse($lastRun.startTime)) | |
Write-Host "Completed in" $elapsedTime.ToString() | |
Write-Host "Completed at" $lastRun.finishTime | |
if ($lastRun.result -eq "failed") { | |
Write-Host "The last pipeline run failed." -ForegroundColor Red | |
} | |
elseif ($lastRun.result -eq "cancelled") { | |
Write-Host "The last pipeline run was cancelled." -ForegroundColor Yellow | |
} | |
elseif ($lastRun.result -eq "succeeded") { | |
Write-Host "The last pipeline run succeeded." -ForegroundColor Green | |
} | |
else { | |
Write-Host "The last pipeline run goofed up." -ForegroundColor Yellow | |
} | |
if ($lastRun.result -eq "succeeded" -or $lastRun.result -eq "failed") { | |
# Let's see if there is artifacts. | |
$artifacts = Invoke-RestMethod ($lastRun.url + "/artifacts") | |
if ($artifacts.count -eq 0) { | |
Write-Host -ForegroundColor Yellow "No artifacts were created in the last run." | |
} | |
else { | |
# Lets show the Installer Verification if it exists. | |
$validationResult = $null | |
foreach ($i in $artifacts.value) { | |
if ($i.name -eq "ValidationResult") { | |
# Found it | |
$validationResult = $i | |
} | |
} | |
if ($null -eq $validationResult) { | |
Write-Host -ForegroundColor Yellow "There were artifacts, but no validation result. :(" | |
} | |
# Download the validation result. | |
Invoke-WebRequest -Uri $validationResult.resource.downloadUrl -UseBasicParsing -OutFile ($env:TEMP + "\ValidationResult" + $lastRun.id + ".zip") | |
Expand-Archive ($env:TEMP + "\ValidationResult" + $lastRun.id + ".zip") -DestinationPath ($env:TEMP + "\ValidationResult" + $lastRun.id + "\") -Force | |
$installVerification = $null | |
try { | |
$installVerification = Get-Content ($env:TEMP + "\ValidationResult" + $lastRun.id + "\ValidationResult\InstallationVerification.json") | ConvertFrom-Json | |
Remove-Item ($env:TEMP + "\ValidationResult" + $lastRun.id) -Recurse -Force | |
} | |
catch { | |
Write-Host -ForegroundColor Yellow "No InstallationVerification.json file found. Darn." | |
} | |
if ($null -ne $installVerification) { | |
$arpEntries = @() | |
foreach ($i in $installVerification.AnalysisResults) { | |
$arpEntry = @{} | |
foreach ($j in $i.FieldsMetadata) { | |
if ($j.Field -ne "KeyPath") { | |
if ($j.Field -eq "Key") { | |
$arpEntry["ProductCode"] = $j.Message | |
} | |
else { | |
$arpEntry[$j.Field] = $j.Message | |
} | |
} | |
} | |
$arpEntries += [PSCustomObject]$arpEntry | |
} | |
if ($arpEntries.Count -ne 0) | |
{ | |
Write-Host "ARP Entries for this pipeline: " | |
$arpEntries | Select-Object | Format-Table -AutoSize | |
} | |
} | |
} | |
} | |
} | |
Write-Host "URL for run:" $lastRun._links.web.href |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment