[CmdletBinding()] param( [Parameter(Mandatory)][string]$RuntimeRepo, [Parameter(Mandatory)][ValidatePattern('^[0-9a-f]{40}$')][string]$RuntimeCommit, [Parameter(Mandatory)][string]$PackagingRepo, [Parameter(Mandatory)][ValidatePattern('^[0-9a-f]{40}$')][string]$PackagingCommit, [Parameter(Mandatory)][string]$Repository, [switch]$Rebuild, [switch]$PackagingPush ) $ErrorActionPreference = 'Stop' $tagPattern = '^runtime-(?[0-9a-f]{7,40})(?:-p(?[1-9][0-9]*))?$' function Invoke-VersionCommand([string]$command, [string[]]$argv) { $result = & $command @argv if ($LASTEXITCODE -ne 0) { throw "$command $($argv -join ' ') failed ($LASTEXITCODE)" } return $result } function Test-InputsChanged([string]$Repo, [string]$From, [string]$To, [string[]]$Paths) { & git -C $Repo diff --quiet $From $To -- @Paths if ($LASTEXITCODE -gt 1) { throw "Could not compare suspend inputs from $From to $To" } return $LASTEXITCODE -eq 1 } function New-VersionPlan([string]$ReleaseId, [string]$Family, [string]$Evidence = '', [string]$Predecessor = '') { return [pscustomobject]@{ Skip = $false ReleaseId = $ReleaseId SuspendCompatID = $Family Evidence = $Evidence Predecessor = $Predecessor } } $remoteTags = @{} foreach ($line in (Invoke-VersionCommand git @('-C', $RuntimeRepo, 'ls-remote', '--tags', 'origin', 'refs/tags/runtime-*'))) { if ($line -match '^(?[0-9a-f]{40})\s+refs/tags/(?runtime-[^\s^]+)(?\^\{\})?$') { if ($Matches.peeled -or !$remoteTags.ContainsKey($Matches.tag)) { $remoteTags[$Matches.tag] = $Matches.sha } } } $pages = (Invoke-VersionCommand gh @('api', '--paginate', '--slurp', "repos/$Repository/releases?per_page=100")) -join "`n" $releasePages = $pages | ConvertFrom-Json -NoEnumerate $published = @(foreach ($page in $releasePages) { foreach ($release in $page) { if ($release.draft -or $release.tag_name -notmatch $tagPattern) { continue } $family = $Matches.base $revision = if ($Matches.revision) { [int]$Matches.revision } else { 0 } $tag = $release.tag_name if (!$remoteTags.ContainsKey($tag)) { throw "Published runtime tag $tag was not found in Git" } $packaging = if ($release.body -match '(?m)^Packaging commit: `([0-9a-f]{40})`\s*$') { $Matches[1] } else { '' } $verifiedFamily = if ($release.body -match '(?m)^Suspend compatibility ID: `([0-9a-f]{7,40})`\s*$') { $Matches[1] } else { '' } [pscustomobject]@{ Tag = $tag RuntimeCommit = $remoteTags[$tag] Packaging = $packaging Family = $family Revision = $revision VerifiedFamily = $verifiedFamily PublishedAt = [DateTimeOffset]$release.published_at } } }) $sameRuntime = @($published | Where-Object RuntimeCommit -eq $RuntimeCommit) if ($sameRuntime.Count -and (!$Rebuild -or ($PackagingPush -and ($sameRuntime | Where-Object Packaging -eq $PackagingCommit)))) { Write-Host "Skipping the already published runtime $RuntimeCommit." return [pscustomobject]@{ Skip = $true } } # The verification belongs to the changed commit and names its exact other input. $approvalRepo = if ($PackagingPush -or $Rebuild) { $PackagingRepo } else { $RuntimeRepo } $approvalCommit = if ($PackagingPush -or $Rebuild) { $PackagingCommit } else { $RuntimeCommit } $otherInput = if ($PackagingPush -or $Rebuild) { $RuntimeCommit } else { $PackagingCommit } $message = (Invoke-VersionCommand git @('-C', $approvalRepo, 'show', '-s', '--format=%B', $approvalCommit)) -join "`n" $trailers = $message | git interpret-trailers --parse if ($LASTEXITCODE -ne 0) { throw 'Could not read suspend compatibility trailers' } $approval = @{} foreach ($line in $trailers) { if ($line -match '^(Suspend-Compatible-With|Suspend-Verified-Inputs|Suspend-Verification):\s+(.+)$') { if ($approval.ContainsKey($Matches[1])) { throw "Repeated compatibility trailer: $($Matches[1])" } $approval[$Matches[1]] = $Matches[2].Trim() } } if ($approval.Count) { $previous = $published | Where-Object Tag -eq $approval['Suspend-Compatible-With'] $evidence = $approval['Suspend-Verification'] if (!$previous -or !$previous.Packaging -or $previous.VerifiedFamily -ne $previous.Family -or $approval['Suspend-Verified-Inputs'] -ne $otherInput -or $evidence -notmatch '^https://[^\s<>]+$') { Write-Warning 'Compatibility evidence does not match these inputs and a published compatibility baseline.' } else { $latest = $published | Sort-Object PublishedAt, Revision -Descending | Select-Object -First 1 $familyTip = $published | Where-Object Family -eq $previous.Family | Sort-Object Revision -Descending | Select-Object -First 1 & git -C $RuntimeRepo merge-base --is-ancestor $previous.RuntimeCommit $RuntimeCommit if ($LASTEXITCODE -gt 1) { throw 'Could not verify the runtime baseline ancestry' } $ancestor = $LASTEXITCODE -eq 0 # Direct changes to these inputs require a fresh family even with a trailer. $runtimePaths = @( 'vendor/qemu', 'guest', 'firmware', ':(glob)crates/reims-vgpu*/**', '.cargo', 'Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'reims-go-runtime.json', 'scripts/install-ctl.sh', 'scripts/install.ps1', 'crates/reims-ctl/Cargo.toml', 'crates/reims-ctl/Cargo.lock', 'crates/reims-ctl/src/qemu.rs', 'crates/reims-ctl/src/runtime.rs', 'crates/reims-ctl/src/main.rs', 'crates/reims-ctl/src/cli.rs', 'crates/reims-ctl/src/vm.rs', 'crates/reims-ctl/src/opencore.rs', 'crates/reims-ctl/src/reims_util.rs', 'crates/reims-ctl/src/host.rs', 'crates/reims-ctl/src/os' ) $packagingPaths = @( ':(glob)packaging/windows-runtime/patches/*.patch', 'packaging/windows-runtime/patches/series.txt', 'packaging/windows-runtime/scripts/apply-patch-series.ps1' ) if ($ancestor -and $previous.Tag -eq $latest.Tag -and $previous.Tag -eq $familyTip.Tag) { & git -C $PackagingRepo cat-file -e "$($previous.Packaging)^{commit}" 2>$null if ($LASTEXITCODE -ne 0) { Invoke-VersionCommand git @('-C', $PackagingRepo, 'fetch', '-q', '--no-tags', 'origin', $previous.Packaging) } $runtimeChange = Test-InputsChanged $RuntimeRepo $previous.RuntimeCommit $RuntimeCommit $runtimePaths $packagingChange = Test-InputsChanged $PackagingRepo $previous.Packaging $PackagingCommit $packagingPaths if (!$runtimeChange -and !$packagingChange) { $id = "$($previous.Family)-p$($familyTip.Revision + 1)" if ($remoteTags.ContainsKey("runtime-$id")) { throw "Runtime tag runtime-$id is already reserved" } return New-VersionPlan $id $previous.Family $evidence $previous.Tag } Write-Warning 'Suspend inputs changed. A new runtime family is required.' } else { Write-Warning 'The verification must cover the latest published runtime and its highest family revision.' } } } $base = (Invoke-VersionCommand git @('-C', $RuntimeRepo, 'rev-parse', '--short=7', $RuntimeCommit)).Trim() if ($sameRuntime.Count -or $remoteTags.ContainsKey("runtime-$base")) { throw 'A new runtime baseline commit is required, or record verified compatibility for these exact build inputs.' } return New-VersionPlan $base $base