diff --git a/.github/workflows/build-runtime.yml b/.github/workflows/build-runtime.yml index 731dfa1..48dae3a 100644 --- a/.github/workflows/build-runtime.yml +++ b/.github/workflows/build-runtime.yml @@ -132,7 +132,7 @@ jobs: git -C $work submodule update --init --depth 1 vendor/qemu if ($LASTEXITCODE) { git -C $work submodule update --init vendor/qemu } if ($LASTEXITCODE) { throw 'vendor/qemu submodule failed' } - $short = (git -C $work rev-parse --short HEAD).Trim() + $short = (git -C $work rev-parse --short=7 HEAD).Trim() $releaseId = "$short${{ needs.resolve.outputs.suffix }}" "short=$short" >> $env:GITHUB_OUTPUT "release_id=$releaseId" >> $env:GITHUB_OUTPUT diff --git a/scripts/pack-runtime.ps1 b/scripts/pack-runtime.ps1 index 28339f5..74dc630 100644 --- a/scripts/pack-runtime.ps1 +++ b/scripts/pack-runtime.ps1 @@ -160,40 +160,39 @@ foreach ($targetName in $byTarget.Keys) { $group = $byTarget[$targetName] $repo = $group[0].Repo $paths = @($group | ForEach-Object { $_.Paths } | Where-Object { $_ } | Select-Object -Unique) - $diffArgs = @('-C', $repo, '-c', 'core.autocrlf=false', 'diff') - if ($paths.Count) { $diffArgs += $paths } + # Use --full-index so blob hash abbreviation lengths match regardless of + # object count between the upstream clone and the single-commit verify repo. + $diffArgs = @('-C', $repo, '-c', 'core.autocrlf=false', 'diff', '--full-index') + if ($paths.Count) { $diffArgs += '--'; $diffArgs += $paths } $treeDiff = (& git @diffArgs | Out-String).Replace("`r`n", "`n").TrimEnd() - if ($group.Count -eq 1) { - $patchText = [IO.File]::ReadAllText((Join-Path $patchesDir $group[0].Name)).Replace("`r`n", "`n").TrimEnd() - if ($treeDiff -ne $patchText) { - throw "$($group[0].Name) does not match the build tree's diff in $repo. Stop: don't edit patches automatically (AGENTS.md rule 4)." + # Apply the declared patch stack to a clean temporary clone of HEAD and compare diffs byte-for-byte. + $verifyDir = Join-Path $TempRoot ("patch-verify-" + [guid]::NewGuid()) + try { + New-Item -ItemType Directory -Force -Path $verifyDir | Out-Null + $headRev = (git -C $repo rev-parse HEAD).Trim() + Invoke-Native 'git' @('init', '-q', $verifyDir) + $tar = Join-Path $TempRoot ("patch-verify-" + [guid]::NewGuid() + '.tar') + Invoke-Native 'git' @('-C', $repo, 'archive', '--format=tar', '-o', $tar, $headRev) + Invoke-Native 'tar.exe' @('-xf', $tar, '-C', $verifyDir) + Remove-Item -LiteralPath $tar -Force + Invoke-Native 'git' @('-C', $verifyDir, '-c', 'user.name=verify', '-c', 'user.email=verify@local', 'add', '-A') + Invoke-Native 'git' @('-C', $verifyDir, '-c', 'user.name=verify', '-c', 'user.email=verify@local', 'commit', '-q', '-m', 'base') + foreach ($ps in $group) { + $pf = Join-Path $patchesDir $ps.Name + Invoke-Native 'git' @('-C', $verifyDir, 'apply', '--check', $pf) + Invoke-Native 'git' @('-C', $verifyDir, 'apply', $pf) } - } else { - # Apply the declared patch stack to a clean temporary clone of HEAD and compare diffs byte-for-byte. - $verifyDir = Join-Path $TempRoot ("patch-verify-" + [guid]::NewGuid()) - try { - New-Item -ItemType Directory -Force -Path $verifyDir | Out-Null - $headRev = (git -C $repo rev-parse HEAD).Trim() - Invoke-Native 'git' @('init', '-q', $verifyDir) - $tar = Join-Path $TempRoot ("patch-verify-" + [guid]::NewGuid() + '.tar') - Invoke-Native 'git' @('-C', $repo, 'archive', '--format=tar', '-o', $tar, $headRev) - Invoke-Native 'tar.exe' @('-xf', $tar, '-C', $verifyDir) - Remove-Item -LiteralPath $tar -Force - Invoke-Native 'git' @('-C', $verifyDir, '-c', 'user.name=verify', '-c', 'user.email=verify@local', 'add', '-A') - Invoke-Native 'git' @('-C', $verifyDir, '-c', 'user.name=verify', '-c', 'user.email=verify@local', 'commit', '-q', '-m', 'base') - foreach ($ps in $group) { - $pf = Join-Path $patchesDir $ps.Name - Invoke-Native 'git' @('-C', $verifyDir, 'apply', '--check', $pf) - Invoke-Native 'git' @('-C', $verifyDir, 'apply', $pf) - } - $expectedDiff = (& git -C $verifyDir -c core.autocrlf=false diff | Out-String).Replace("`r`n", "`n").TrimEnd() - if ($treeDiff -ne $expectedDiff) { - throw "Patch stack ($(($group | ForEach-Object { $_.Name }) -join ', ')) does not match the build tree's diff in $repo. Stop: don't edit patches automatically (AGENTS.md rule 4)." - } - } finally { - if (Test-Path -LiteralPath $verifyDir) { Remove-Item -Recurse -Force -LiteralPath $verifyDir } + $expectedDiff = (& git -C $verifyDir -c core.autocrlf=false diff --full-index | Out-String).Replace("`r`n", "`n").TrimEnd() + if ($treeDiff -ne $expectedDiff) { + $treeStat = (& git -C $repo diff --stat -- @paths | Out-String).Trim() + $expStat = (& git -C $verifyDir diff --stat | Out-String).Trim() + Write-Host "Build tree diff --stat:`n$treeStat" + Write-Host "Expected patch stack diff --stat:`n$expStat" + throw "Patch stack ($(($group | ForEach-Object { $_.Name }) -join ', ')) does not match the build tree's diff in $repo. Stop: don't edit patches automatically (AGENTS.md rule 4)." } + } finally { + if (Test-Path -LiteralPath $verifyDir) { Remove-Item -Recurse -Force -LiteralPath $verifyDir } } } # Anything else changed in the build trees is undeclared: refuse.