name: Build Portable Runtime (Alpha) # Daily: build the newest steelbrain/reims-vgpu commit with the patch queue # (patches/series.txt) and publish it as a GitHub prerelease = the alpha # channel (portable-runtime-spec.md section 6). Never publishes stable: # promotion needs a real-host smoke test and a person (AGENTS.md rule 6). on: schedule: - cron: "23 3 * * *" # 03:23 UTC daily; skipped when upstream has not moved workflow_dispatch: inputs: upstream_commit: description: "steelbrain/reims-vgpu commit (empty = upstream default branch HEAD)" required: false default: "" publish: 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 issues: write concurrency: group: build-runtime cancel-in-progress: false env: UPSTREAM_URL: https://github.com/steelbrain/reims-vgpu.git KEEP_ALPHAS: "7" # unpromoted alpha prereleases kept; older ones are deleted jobs: resolve: runs-on: ubuntu-latest 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 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 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 if: needs.resolve.outputs.skip != 'true' runs-on: windows-latest 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 }} steps: - uses: actions/checkout@v4 - name: Setup MSYS2 CLANG64 id: msys2 uses: msys2/setup-msys2@v2 with: msystem: CLANG64 update: true install: >- git zstd tar mingw-w64-clang-x86_64-toolchain mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-meson mingw-w64-clang-x86_64-ninja mingw-w64-clang-x86_64-pkgconf mingw-w64-clang-x86_64-glib2 mingw-w64-clang-x86_64-pixman mingw-w64-clang-x86_64-gtk3 mingw-w64-clang-x86_64-libslirp mingw-w64-clang-x86_64-libusb mingw-w64-clang-x86_64-libva mingw-w64-clang-x86_64-mesa mingw-w64-clang-x86_64-vulkan-loader mingw-w64-clang-x86_64-python mingw-w64-clang-x86_64-python-pip - name: Check out upstream and apply the patch queue id: patches shell: pwsh run: | $ErrorActionPreference = 'Stop' $work = Join-Path $env:RUNNER_TEMP 'reims-vgpu' foreach ($d in 'cargo', 'xdg-data', 'xdg-cache') { New-Item -ItemType Directory -Force -Path (Join-Path $env:RUNNER_TEMP $d) | Out-Null } # The runner's git defaults to core.autocrlf=true; LF patches need an LF # checkout (upstream also rewrites CRLF files to LF, install-ctl.sh). git config --global core.autocrlf false git clone -q $env:UPSTREAM_URL $work if ($LASTEXITCODE) { throw 'clone failed' } git -C $work checkout -q '${{ needs.resolve.outputs.commit }}' if ($LASTEXITCODE) { throw 'checkout failed' } 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=7 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). $resultFile = Join-Path $env:RUNNER_TEMP 'patches.json' try { pwsh -NoProfile -File scripts/apply-patch-series.ps1 -ReimsRepo $work -ResultFile $resultFile $ok = $LASTEXITCODE -eq 0 } finally { if (Test-Path $resultFile) { $r = Get-Content -Raw $resultFile | ConvertFrom-Json "applied=$(@($r.applied) -join ',')" >> $env:GITHUB_OUTPUT "merged=$(@($r.merged) -join ',')" >> $env:GITHUB_OUTPUT "conflict=$($r.conflict)" >> $env:GITHUB_OUTPUT "APPLIED_PATCHES=$(@($r.applied) -join ',')" >> $env:GITHUB_ENV } } 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 - name: Build upstream runtime in MSYS2 CLANG64 shell: msys2 {0} env: REIMS_INSTALL_SKIP_HOST_CHECKS: "1" run: | set -euo pipefail cd "$(cygpath -u "$UPSTREAM_DIR")" # Upstream's own non-interactive CLANG64 build script. bash scripts/install-ctl.sh --yes - name: Package alpha runtime and source archives shell: pwsh run: | $ErrorActionPreference = 'Stop' $outDir = Join-Path $env:RUNNER_TEMP 'releases' New-Item -ItemType Directory -Force -Path $outDir | Out-Null # In-process call, so an empty list (every patch already upstream) binds # as an empty array rather than being dropped as an empty argument. $applied = @($env:APPLIED_PATCHES -split ',' | Where-Object { $_ }) & ./scripts/pack-runtime.ps1 ` -ReimsRepo $env:UPSTREAM_DIR ` -CargoHome $env:CARGO_HOME ` -QemuDir (Join-Path $env:XDG_DATA_HOME 'reims-ctl\qemu\current') ` -Msys2 '${{ steps.msys2.outputs.msys2-location }}' ` -OutDir $outDir ` -TempRoot $env:RUNNER_TEMP ` -Channel alpha ` -ReleaseId $env:RELEASE_ID ` -Patches $applied - name: Alpha entry gate shell: pwsh run: | $ErrorActionPreference = 'Stop' & ./scripts/check-runtime-alpha.ps1 ` -OutDir (Join-Path $env:RUNNER_TEMP 'releases') ` -Commit $env:RELEASE_ID -RequireSlim ` -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.RELEASE_ID }}-alpha path: | ${{ runner.temp }}/releases/reims-runtime-*.tar.zst ${{ runner.temp }}/releases/SHA256SUMS.txt retention-days: 14 - name: Publish alpha prerelease (never stable) if: github.event_name == 'schedule' || inputs.publish env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} MERGED: ${{ steps.patches.outputs.merged }} shell: pwsh run: | $ErrorActionPreference = 'Stop' $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", "reims-runtime-symbols-$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 (``$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). Local patches applied (sources and patches are in the attached source packages): $applied$merged The optional ``reims-runtime-symbols-$c.tar.zst`` contains matching debug files for crash analysis. Build: $env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID "@ gh release create "runtime-$c" @assets --prerelease --title "Portable Runtime runtime-$c (alpha)" --notes $notes if ($LASTEXITCODE) { throw "gh release create failed ($LASTEXITCODE)" } - name: Prune old alpha prereleases if: github.event_name == 'schedule' || inputs.publish env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} shell: pwsh run: | # Only unpromoted runtime prereleases; stable releases are never touched. $alphas = gh release list -R $env:GITHUB_REPOSITORY --limit 1000 --json tagName,isPrerelease,isDraft,createdAt | ConvertFrom-Json | Where-Object { $_.tagName -like 'runtime-*' -and $_.isPrerelease -and -not $_.isDraft } | Sort-Object createdAt -Descending $alphas | Select-Object -Skip ([int]$env:KEEP_ALPHAS) | ForEach-Object { Write-Host "Deleting old alpha $($_.tagName)" gh release delete $_.tagName -R $env:GITHUB_REPOSITORY --yes --cleanup-tag } report: needs: [resolve, build] if: always() && needs.resolve.outputs.skip != 'true' && (failure() || needs.build.outputs.merged != '') runs-on: ubuntu-latest steps: - env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} RESULT: ${{ needs.build.result }} COMMIT: ${{ needs.resolve.outputs.commit }} CONFLICT: ${{ needs.build.outputs.conflict }} MERGED: ${{ needs.build.outputs.merged }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} run: | set -euo pipefail # One open issue per kind; later runs add a comment instead of a new issue. file_issue() { local title="$1" body="$2" n n="$(gh issue list -R "$GITHUB_REPOSITORY" --state open --search "in:title \"$title\"" --json number,title -q ".[] | select(.title == \"$title\") | .number" | head -n1)" if [ -n "$n" ]; then gh issue comment "$n" -R "$GITHUB_REPOSITORY" --body "$body" else gh issue create -R "$GITHUB_REPOSITORY" --title "$title" --body "$body" fi } if [ "$RESULT" != "success" ]; then if [ -n "$CONFLICT" ]; then why="Patch \`$CONFLICT\` neither applies to upstream \`$COMMIT\` nor is already there. Per AGENTS.md rule 4 the patch was not edited; a person decides how to rebase or retire it." else why="The build, packaging or alpha gate failed for upstream \`$COMMIT\`; see the log." fi file_issue "Runtime alpha build failed" "$why"$'\n\n'"Run: $RUN_URL"$'\n\n'"No alpha was published." fi if [ -n "$MERGED" ]; then file_issue "Patch queue: patches already upstream" "Upstream \`$COMMIT\` already contains: \`$MERGED\`. They were skipped. Record the merge commit in portable-runtime-spec.md section 5, then remove them from patches/ and patches/series.txt."$'\n\n'"Run: $RUN_URL" fi