diff --git a/.github/workflows/build-runtime.yml b/.github/workflows/build-runtime.yml index 9f80162..731dfa1 100644 --- a/.github/workflows/build-runtime.yml +++ b/.github/workflows/build-runtime.yml @@ -17,6 +17,10 @@ on: description: "Publish as an alpha prerelease (never stable)" type: boolean default: true + rebuild: + description: "Build a new patch revision (runtime--pN) even if this upstream commit is already released" + type: boolean + default: false permissions: contents: write @@ -36,22 +40,50 @@ jobs: outputs: commit: ${{ steps.r.outputs.commit }} skip: ${{ steps.r.outputs.skip }} + suffix: ${{ steps.r.outputs.suffix }} steps: - id: r env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} WANT: ${{ inputs.upstream_commit }} + REBUILD: ${{ inputs.rebuild }} run: | set -euo pipefail git clone -q --filter=blob:none --no-checkout "$UPSTREAM_URL" up commit="$(git -C up rev-parse --verify "${WANT:-HEAD}^{commit}")" echo "commit=$commit" >> "$GITHUB_OUTPUT" - # Already published (alpha or stable) under any short-hash length? - skip=false + # Already published (alpha or stable) under any short-hash length or -pN revision? + max_rev=0 for tag in $(gh release list -R "$GITHUB_REPOSITORY" --limit 1000 --json tagName -q '.[].tagName' | grep '^runtime-' || true); do - case "$commit" in "${tag#runtime-}"*) skip=true; echo "Upstream $commit is already released as $tag";; esac + rest="${tag#runtime-}" + base="${rest%%-p*}" + case "$commit" in + "$base"*) + rev=1 + if [ "$rest" != "$base" ]; then + num="${rest#"$base"-p}" + case "$num" in + ''|*[!0-9]*) ;; + *) rev="$num" ;; + esac + fi + if [ "$rev" -gt "$max_rev" ]; then max_rev="$rev"; fi + echo "Upstream $commit is already released as $tag (rev $rev)" + ;; + esac done + skip=false + suffix="" + if [ "$max_rev" -gt 0 ]; then + if [ "$REBUILD" = "true" ]; then + suffix="-p$((max_rev + 1))" + echo "Rebuild requested: will publish with suffix $suffix" + else + skip=true + fi + fi echo "skip=$skip" >> "$GITHUB_OUTPUT" + echo "suffix=$suffix" >> "$GITHUB_OUTPUT" build: needs: resolve @@ -60,6 +92,7 @@ jobs: timeout-minutes: 150 outputs: short: ${{ steps.patches.outputs.short }} + release_id: ${{ steps.patches.outputs.release_id }} applied: ${{ steps.patches.outputs.applied }} merged: ${{ steps.patches.outputs.merged }} conflict: ${{ steps.patches.outputs.conflict }} @@ -100,7 +133,9 @@ jobs: 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() + $releaseId = "$short${{ needs.resolve.outputs.suffix }}" "short=$short" >> $env:GITHUB_OUTPUT + "release_id=$releaseId" >> $env:GITHUB_OUTPUT # Applies what applies, skips what upstream already has, stops on a # conflict without touching the patch (AGENTS.md rule 4). @@ -120,6 +155,7 @@ jobs: if (-not $ok) { throw 'patch queue does not apply' } "UPSTREAM_DIR=$work" >> $env:GITHUB_ENV "SHORT_COMMIT=$short" >> $env:GITHUB_ENV + "RELEASE_ID=$releaseId" >> $env:GITHUB_ENV "CARGO_HOME=$(Join-Path $env:RUNNER_TEMP 'cargo')" >> $env:GITHUB_ENV "XDG_DATA_HOME=$(Join-Path $env:RUNNER_TEMP 'xdg-data')" >> $env:GITHUB_ENV "XDG_CACHE_HOME=$(Join-Path $env:RUNNER_TEMP 'xdg-cache')" >> $env:GITHUB_ENV @@ -151,6 +187,7 @@ jobs: -OutDir $outDir ` -TempRoot $env:RUNNER_TEMP ` -Channel alpha ` + -ReleaseId $env:RELEASE_ID ` -Patches $applied - name: Alpha entry gate @@ -159,14 +196,14 @@ jobs: $ErrorActionPreference = 'Stop' & ./scripts/check-runtime-alpha.ps1 ` -OutDir (Join-Path $env:RUNNER_TEMP 'releases') ` - -Commit $env:SHORT_COMMIT ` + -Commit $env:RELEASE_ID ` -Zstd (Join-Path '${{ steps.msys2.outputs.msys2-location }}' 'usr\bin\zstd.exe') ` -AppliedPatches @($env:APPLIED_PATCHES -split ',' | Where-Object { $_ }) - name: Upload alpha artifacts uses: actions/upload-artifact@v4 with: - name: reims-runtime-win-x64-${{ env.SHORT_COMMIT }}-alpha + name: reims-runtime-win-x64-${{ env.RELEASE_ID }}-alpha path: | ${{ runner.temp }}/releases/reims-runtime-*.tar.zst ${{ runner.temp }}/releases/SHA256SUMS.txt @@ -180,14 +217,15 @@ jobs: shell: pwsh run: | $ErrorActionPreference = 'Stop' - $c = $env:SHORT_COMMIT + $c = $env:RELEASE_ID + $short = $env:SHORT_COMMIT $dir = Join-Path $env:RUNNER_TEMP 'releases' $assets = @("reims-runtime-win-x64-$c.tar.zst", "reims-runtime-src-$c.tar.zst", "reims-runtime-msys2-src-$c.tar.zst", 'SHA256SUMS.txt') | ForEach-Object { Join-Path $dir $_ } $applied = if ($env:APPLIED_PATCHES) { ($env:APPLIED_PATCHES -split ',' | ForEach-Object { "- ``$_``" }) -join "`n" } else { '- (none)' } $merged = if ($env:MERGED) { "`n`nAlready upstream, skipped (retire from patches/): $env:MERGED" } else { '' } $notes = @" - **Alpha** runtime, built automatically from upstream [steelbrain/reims-vgpu@$c](https://github.com/steelbrain/reims-vgpu/commit/${{ needs.resolve.outputs.commit }}). + **Alpha** runtime (``$c``), built automatically from upstream [steelbrain/reims-vgpu@$short](https://github.com/steelbrain/reims-vgpu/commit/${{ needs.resolve.outputs.commit }}). Not smoke-tested on a real host. It becomes stable only after ``scripts/smoke-runtime.ps1`` passes on a real Windows host and a person approves (portable-runtime-spec.md section 6). diff --git a/frontend/src/components/RuntimeOnline.tsx b/frontend/src/components/RuntimeOnline.tsx index ef9b3a3..8c80b8e 100644 --- a/frontend/src/components/RuntimeOnline.tsx +++ b/frontend/src/components/RuntimeOnline.tsx @@ -42,7 +42,12 @@ export const RuntimeOnline: React.FC = ({ locale, channel, installed, tas const active = installed.find((i) => i.active) ?? installed[0] const latest = remote?.[0] - const isInstalled = (c: string) => installed.some((i) => i.commit.startsWith(c) || c.startsWith(i.commit)) + const sameRuntimeId = (a: string, b: string) => { + const [baseA, revA = ''] = a.split('-', 2) + const [baseB, revB = ''] = b.split('-', 2) + return revA === revB && (baseA.startsWith(baseB) || baseB.startsWith(baseA)) + } + const isInstalled = (c: string) => installed.some((i) => sameRuntimeId(i.commit, c)) const running = task?.status === 'running' const updatable = !!latest && !isInstalled(latest.commit) diff --git a/internal/runtime/remote.go b/internal/runtime/remote.go index 2aeb658..7773e88 100644 --- a/internal/runtime/remote.go +++ b/internal/runtime/remote.go @@ -221,7 +221,8 @@ func nextLink(h string) string { return "" } -// Pick finds a release by commit prefix, or the newest for "" / "latest". +// Pick finds a release by exact ID, revision-matching commit prefix, or the +// newest for "" / "latest". func Pick(list []Remote, want string) (*Remote, error) { want = strings.TrimSpace(want) if len(list) == 0 { @@ -231,7 +232,17 @@ func Pick(list []Remote, want string) (*Remote, error) { return &list[0], nil } for i := range list { - if strings.HasPrefix(list[i].Commit, want) || strings.HasPrefix(want, list[i].Commit) { + if list[i].Commit == want { + return &list[i], nil + } + } + for i := range list { + if sameRuntimeID(list[i].Commit, want) { + return &list[i], nil + } + } + for i := range list { + if strings.HasPrefix(list[i].Commit, want) { return &list[i], nil } } @@ -374,6 +385,29 @@ func DownloadsDir(cfg *config.Config) string { return filepath.Join(cfg.DataRoot, "downloads") } +// splitRuntimeID separates "" and an optional patch-revision suffix +// such as "-p2" in "3731afd-p2". +func splitRuntimeID(id string) (base, rev string) { + if i := strings.IndexByte(id, '-'); i >= 0 { + return id[:i], id[i+1:] + } + return id, "" +} + +// sameRuntimeID reports whether a and b refer to the same runtime build, +// allowing short/full commit prefix matching only within the same revision. +func sameRuntimeID(a, b string) bool { + if a == "" || b == "" { + return false + } + baseA, revA := splitRuntimeID(a) + baseB, revB := splitRuntimeID(b) + if revA != revB { + return false + } + return strings.HasPrefix(baseA, baseB) || strings.HasPrefix(baseB, baseA) +} + // IsInstalled reports whether commit is already unpacked under runtimes/. func IsInstalled(cfg *config.Config, commit string) bool { list, err := List(cfg) @@ -381,7 +415,7 @@ func IsInstalled(cfg *config.Config, commit string) bool { return false } for _, it := range list { - if strings.HasPrefix(it.Commit, commit) || strings.HasPrefix(commit, it.Commit) { + if sameRuntimeID(it.Commit, commit) { return true } } diff --git a/internal/runtime/remote_test.go b/internal/runtime/remote_test.go index 06db8c1..9456e4d 100644 --- a/internal/runtime/remote_test.go +++ b/internal/runtime/remote_test.go @@ -202,3 +202,36 @@ func TestNormalizeChannel(t *testing.T) { } } } + +func TestSameRuntimeIDDistinguishesPatchRevisions(t *testing.T) { + cases := []struct { + a, b string + want bool + }{ + {"3731afd", "3731afd", true}, + {"3731afd", "3731afd9b134", true}, + {"3731afd", "3731afd-p2", false}, + {"3731afd-p2", "3731afd", false}, + {"3731afd-p2", "3731afd-p2", true}, + {"3731afd-p2", "3731afd-p3", false}, + {"3731afd-p2", "3731afd9b134-p2", true}, + } + for _, tc := range cases { + if got := sameRuntimeID(tc.a, tc.b); got != tc.want { + t.Errorf("sameRuntimeID(%q, %q) = %v, want %v", tc.a, tc.b, got, tc.want) + } + } + list := []Remote{ + {Commit: "3731afd-p2", Channel: ChannelAlpha}, + {Commit: "3731afd", Channel: ChannelStable}, + } + if r, err := Pick(list, "3731afd-p2"); err != nil || r.Commit != "3731afd-p2" { + t.Fatalf("Pick(-p2) = %+v, %v", r, err) + } + if r, err := Pick(list, "3731afd"); err != nil || r.Commit != "3731afd" { + t.Fatalf("Pick(base) = %+v, %v", r, err) + } + if r, err := Pick(list, "latest"); err != nil || r.Commit != "3731afd-p2" { + t.Fatalf("Pick(latest) = %+v, %v", r, err) + } +} diff --git a/scripts/pack-runtime.ps1 b/scripts/pack-runtime.ps1 index 09f7716..28339f5 100644 --- a/scripts/pack-runtime.ps1 +++ b/scripts/pack-runtime.ps1 @@ -43,6 +43,9 @@ param( [ValidateSet('alpha', 'stable')] [string]$Channel = 'alpha', [int]$ZstdLevel = 15, + # Release identifier for archive names and manifest.commit (defaults to short + # upstream commit; e.g. "3731afd-p2" for a patch-queue rebuild of 3731afd). + [string]$ReleaseId = '', # Names from patches/series.txt actually applied. Not given: all of them. # Given but empty: none (every patch already upstream). [string[]]$Patches = @() @@ -93,6 +96,7 @@ foreach ($p in @($ctlExe, $utilExe, $qemuExe)) { $commit = (git -C $ReimsRepo rev-parse --short HEAD).Trim() $fullCommit = (git -C $ReimsRepo rev-parse HEAD).Trim() +$id = if ($ReleaseId -and $ReleaseId.Trim()) { $ReleaseId.Trim() } else { $commit } $qemuRepo = Join-Path $ReimsRepo 'vendor\qemu' $qemuCommit = (git -C $qemuRepo rev-parse HEAD).Trim() @@ -206,9 +210,9 @@ if ($otherCtl.Count -or $otherQemu.Count) { throw "Undeclared changes in the build trees:`n$($otherCtl + $otherQemu -join "`n")" } -$bundleName = "reims-runtime-win-x64-$commit" -$srcName = "reims-runtime-src-$commit" -$stageRoot = Join-Path $TempRoot "pack-$commit" +$bundleName = "reims-runtime-win-x64-$id" +$srcName = "reims-runtime-src-$id" +$stageRoot = Join-Path $TempRoot "pack-$id" $bundleDir = Join-Path $stageRoot $bundleName $srcDir = Join-Path $stageRoot $srcName if (Test-Path -LiteralPath $stageRoot) { Remove-Item -Recurse -Force -LiteralPath $stageRoot } @@ -260,7 +264,7 @@ $msysText = @" # (pacman -Qo on the build machine, $(Get-Date -Format 'yyyy-MM-dd')). # # Sources: every package whose licence requires source (GPL / LGPL / MPL) is in -# reims-runtime-msys2-src-$commit.tar.zst, published beside this runtime. +# reims-runtime-msys2-src-$id.tar.zst, published beside this runtime. # The same files are also at: # https://repo.msys2.org/mingw/sources/ (-.src.tar.zst, by pkgbase) # https://github.com/msys2/MINGW-packages (build recipes) @@ -340,7 +344,7 @@ $manifest = [ordered]@{ name = $bundleName platform = 'windows-x86_64' upstream_repo = 'https://github.com/steelbrain/reims-vgpu' - commit = $commit + commit = $id full_commit = $fullCommit vendor_qemu_commit = $qemuCommit util_commit = $utilCommit @@ -372,7 +376,7 @@ Write-Utf8 "$runtimeArchive.sha256" "$rtHash $bundleName.tar.zst`n" Write-Utf8 (Join-Path $OutDir 'SHA256SUMS.txt') "$rtHash $bundleName.tar.zst`n$srcHash $srcName.tar.zst`n" # Sources of the copyleft MSYS2 packages, as their own asset (adds a line to SHA256SUMS.txt). -& (Join-Path $PSScriptRoot 'pack-msys2-sources.ps1') -PackagesFile (Join-Path $bundleDir 'MSYS2-PACKAGES.txt') -Commit $commit -OutDir $OutDir -Msys2 $Msys2 -TempRoot $TempRoot +& (Join-Path $PSScriptRoot 'pack-msys2-sources.ps1') -PackagesFile (Join-Path $bundleDir 'MSYS2-PACKAGES.txt') -Commit $id -OutDir $OutDir -Msys2 $Msys2 -TempRoot $TempRoot Remove-Item -Recurse -Force -LiteralPath $stageRoot