Files
Reims-Go/.github/workflows/release.yml
千川白浪 107a8d73e0 refactor: 收拢核心管线、强化错误处理、优化热路径与更新体积 (#200)
* refactor: 收拢核心管线、强化错误处理、优化热路径与更新体积

* fix: preserve download recovery and bound PBZX decoding

Keep VM diagnostics available during plugin initialization failures and verify settings through the unified driver lifecycle.
2026-12-05 20:54:41 +08:00

214 lines
8.4 KiB
YAML

name: Release Reims-Go
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Release tag to build & publish (e.g. v0.2.9 or v0.2.9-alpha.1)"
required: true
workflow_call:
inputs:
tag:
description: "Existing release tag to build & publish"
required: true
type: string
permissions:
contents: write
env:
GOCACHE: ${{ github.workspace }}/.debug/cache/go-build
jobs:
release:
runs-on: windows-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || '' }}
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- uses: pnpm/action-setup@v4
with:
version: 10
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: frontend/pnpm-lock.yaml
- name: Resolve version tag and channel
env:
# Set for manual runs and for calls from the daily alpha workflow; empty for tag pushes.
INPUT_TAG: ${{ inputs.tag }}
REF_NAME: ${{ github.ref_name }}
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$tag = if ($env:INPUT_TAG) { $env:INPUT_TAG } else { $env:REF_NAME }
$tag = $tag.Trim()
if ($tag -match '^v[0-9]+\.[0-9]+\.[0-9]+$') {
$channel = 'stable'
} elseif ($tag -match '^v[0-9]+\.[0-9]+\.[0-9]+-alpha(?:[.-][0-9A-Za-z.-]+)?$') {
$channel = 'alpha'
} else {
throw "Release tag must be stable (vX.Y.Z) or alpha test (vX.Y.Z-alpha[.N]), got: $tag"
}
"RELEASE_TAG=$tag" | Out-File -FilePath $env:GITHUB_ENV -Append
"RELEASE_CHANNEL=$channel" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Host "Resolved tag=$tag channel=$channel"
- name: Generate release notes
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$tag = $env:RELEASE_TAG
$channel = $env:RELEASE_CHANNEL
New-Item -ItemType Directory -Force -Path .debug/runs/release | Out-Null
$notesFile = Join-Path $PWD ".debug/runs/release/release-notes-$tag.md"
& ./scripts/build-release-notes.ps1 `
-Tag $tag `
-Channel $channel `
-ChangelogPath 'CHANGELOG.md' `
-Repo $env:GITHUB_REPOSITORY `
-DiscoverStableRuntime `
-OutFile $notesFile
"RELEASE_NOTES_FILE=$notesFile" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Host "Generated $channel release notes ($((Get-Item -LiteralPath $notesFile).Length) bytes) for $tag"
- name: Install frontend dependencies
shell: pwsh
run: pnpm --dir frontend install --frozen-lockfile
- name: Release tests
shell: pwsh
run: node scripts/test.mjs release
- name: Bundle frontend
shell: pwsh
run: pnpm --dir frontend bundle
- name: Install Wails CLI
shell: pwsh
run: go install github.com/wailsapp/wails/v2/cmd/wails@v2.17.1
- name: Build Windows x64 binary
shell: pwsh
env:
CGO_ENABLED: "0"
run: |
$ErrorActionPreference = 'Stop'
$tag = $env:RELEASE_TAG
$dist = 'dist-release'
New-Item -ItemType Directory -Force -Path $dist | Out-Null
$verPkg = 'github.com/Nwflower/reims-go/internal/version'
# One executable: the window without arguments, command-line mode with a command.
$guiOut = Join-Path $dist "reims-go-$tag-windows-amd64.exe"
wails build -s -trimpath -ldflags "-s -w -X $verPkg.Version=$tag" -o "reims-go-$tag-windows-amd64.exe"
if ($LASTEXITCODE) { throw "wails build failed ($LASTEXITCODE)" }
Copy-Item (Join-Path 'build\bin' "reims-go-$tag-windows-amd64.exe") $guiOut
$zipOut = [IO.Path]::ChangeExtension($guiOut, '.zip')
Compress-Archive -LiteralPath @($guiOut, 'LICENSE', 'NOTICE.md') -DestinationPath $zipOut -CompressionLevel Optimal -Force
$lines = @(Get-Item -LiteralPath $guiOut, $zipOut | ForEach-Object {
$h = (Get-FileHash -Algorithm SHA256 -LiteralPath $_.FullName).Hash.ToLowerInvariant()
"$h $($_.Name)"
})
[IO.File]::WriteAllText((Join-Path $dist 'SHA256SUMS.txt'), ($lines -join "`n") + "`n", [Text.UTF8Encoding]::new($false))
Get-Content (Join-Path $dist 'SHA256SUMS.txt')
- name: Verify release artifacts
shell: pwsh
run: ./scripts/check-release-artifact.ps1 -Executable "dist-release/reims-go-$env:RELEASE_TAG-windows-amd64.exe" -Version $env:RELEASE_TAG -Package
- name: WebView2 first-launch smoke
timeout-minutes: 3
run: node scripts/test.mjs webview2 "dist-release/reims-go-$env:RELEASE_TAG-windows-amd64.exe"
- name: Publish GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$tag = $env:RELEASE_TAG
$channel = $env:RELEASE_CHANNEL
$notesFile = $env:RELEASE_NOTES_FILE
if (-not (Test-Path -LiteralPath $notesFile) -or (Get-Item -LiteralPath $notesFile).Length -eq 0) {
throw "Release notes file is missing or empty: $notesFile"
}
$title = if ($channel -eq 'alpha') { "Reims-Go $tag (Alpha)" } else { "Reims-Go $tag" }
$files = @(Get-ChildItem -LiteralPath 'dist-release' -File | Select-Object -ExpandProperty FullName)
$exists = $true
$existingBody = ''
try {
$relJson = gh release view $tag --json body 2>$null
if ($LASTEXITCODE -ne 0) {
$exists = $false
} else {
$existingBody = (($relJson | ConvertFrom-Json).body | Out-String).Trim()
}
} catch {
$exists = $false
}
if ($exists) {
gh release upload $tag @files --clobber
if ($LASTEXITCODE -ne 0) { throw "gh release upload failed ($LASTEXITCODE)" }
$editArgs = @('release', 'edit', $tag, '--title', $title)
if ($channel -eq 'alpha') {
$editArgs += '--prerelease'
} else {
$editArgs += @('--prerelease=false', '--latest')
}
# Backfill notes if the existing release body is empty or only GitHub's auto-generated compare link.
$isAutoOnly = [string]::IsNullOrWhiteSpace($existingBody) -or ($existingBody -match '^\*\*Full Changelog\*\*:\s*https://\S+$')
if ($isAutoOnly) {
$editArgs += @('--notes-file', $notesFile)
}
& gh @editArgs
if ($LASTEXITCODE -ne 0) { throw "gh release edit failed ($LASTEXITCODE)" }
} else {
$createArgs = @('release', 'create', $tag) + $files + @('--title', $title, '--notes-file', $notesFile)
if ($channel -eq 'alpha') {
$createArgs += '--prerelease'
} else {
$createArgs += '--latest'
}
& gh @createArgs
if ($LASTEXITCODE -ne 0) { throw "gh release create failed ($LASTEXITCODE)" }
}
- name: Delete all published alpha test releases after stable release
if: env.RELEASE_CHANNEL == 'stable'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
# Only delete app alpha prereleases (vX.Y.Z-alpha*); never touch runtime-* or the rolling dev release.
$rels = gh release list -R $env:GITHUB_REPOSITORY --limit 1000 --json tagName,isPrerelease,isDraft | ConvertFrom-Json
$alphas = @($rels | Where-Object {
$_.isPrerelease -and
-not $_.isDraft -and
$_.tagName -match '^v[0-9]+\.[0-9]+\.[0-9]+-alpha(?:[.-][0-9A-Za-z.-]+)?$'
})
if ($alphas.Count -eq 0) {
Write-Host "No published alpha test releases to clean up."
exit 0
}
foreach ($rel in $alphas) {
Write-Host "Deleting alpha test release $($rel.tagName)"
gh release delete $rel.tagName -R $env:GITHUB_REPOSITORY --yes --cleanup-tag
if ($LASTEXITCODE -ne 0) {
throw "Failed to delete alpha test release $($rel.tagName) (exit $LASTEXITCODE)"
}
}