Files
Reims-Go/.github/workflows/release.yml
T

155 lines
6.0 KiB
YAML

name: Release Reims-Go
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Release tag to build & publish (e.g. v0.2.1)"
required: true
permissions:
contents: write
jobs:
release:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || '' }}
- 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
shell: pwsh
run: |
$tag = if ('${{ github.event_name }}' -eq 'workflow_dispatch') { '${{ inputs.tag }}' } else { '${{ github.ref_name }}' }
if (-not $tag.StartsWith('v')) { throw "Release tag must start with 'v', got: $tag" }
"RELEASE_TAG=$tag" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Generate release notes from CHANGELOG.md
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$tag = $env:RELEASE_TAG
$runtimeTag = ''
$runtimeTitle = ''
try {
$rels = gh release list -R $env:GITHUB_REPOSITORY --limit 100 --json tagName,name,isPrerelease,isDraft,createdAt | ConvertFrom-Json
$stable = $rels |
Where-Object { $_.tagName -like 'runtime-*' -and -not $_.isPrerelease -and -not $_.isDraft } |
Sort-Object createdAt -Descending |
Select-Object -First 1
if ($stable) {
$runtimeTag = $stable.tagName
$runtimeTitle = if ($stable.name) { $stable.name } else { $stable.tagName }
}
} catch {
Write-Warning "Could not query latest stable runtime release: $_"
}
$notesFile = Join-Path $env:RUNNER_TEMP "release-notes-$tag.md"
& ./scripts/build-release-notes.ps1 `
-Tag $tag `
-ChangelogPath 'CHANGELOG.md' `
-Repo $env:GITHUB_REPOSITORY `
-StableRuntimeTag $runtimeTag `
-StableRuntimeTitle $runtimeTitle `
-OutFile $notesFile
"RELEASE_NOTES_FILE=$notesFile" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Host "Generated release notes ($((Get-Item -LiteralPath $notesFile).Length) bytes) for $tag"
- name: Build frontend
shell: pwsh
run: |
pnpm --dir frontend install --frozen-lockfile
pnpm --dir frontend build
- name: Go test & vet
shell: pwsh
run: |
go test ./...
go vet ./...
- 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
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 -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: Publish GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$tag = $env:RELEASE_TAG
$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"
}
$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)" }
# 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) {
gh release edit $tag --notes-file $notesFile
if ($LASTEXITCODE -ne 0) { throw "gh release edit failed ($LASTEXITCODE)" }
}
} else {
gh release create $tag @files `
--title "Reims-Go $tag" `
--notes-file $notesFile
if ($LASTEXITCODE -ne 0) { throw "gh release create failed ($LASTEXITCODE)" }
}