Files
OpsLog/release.ps1
T

101 lines
5.4 KiB
PowerShell

# OpsLog release script — source → Gitea (origin), exe → Gitea + GitHub releases.
# Mirrors the DXHunter workflow, adapted for the Wails build and OpsLog's version
# files. Run from the repo root in PowerShell.
# Force UTF-8 throughout — prevents git log em-dashes / accents from corrupting the API body
$OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# ── Config ────────────────────────────────────────────────────────────────────
$GitHubRepo = "GregTroar/OpsLog" # GitHub repo that hosts the public exe (adjust if different)
$ExePath = "build/bin/OpsLog.exe" # Wails build output
$Wails = Join-Path $HOME "go\bin\wails.exe" # the v2.11 wails (not the global one)
if (-not (Test-Path $Wails)) { $Wails = "wails" } # fall back to PATH
# Parse token, host, and repo path from the Gitea remote URL (origin)
$remoteUrl = git remote get-url origin
if ($remoteUrl -match 'https://([^@]+)@([^/]+)/(.+?)\.git') {
$token = $Matches[1]
$gitHost = $Matches[2]
$repo = $Matches[3]
} else {
Write-Host "Cannot parse Gitea remote URL (expected https://<token>@<host>/<repo>.git)." -ForegroundColor Red; exit 1
}
git add .
$msg = Read-Host "Commit message"
if ($msg) { git commit -m $msg }
$ver = Read-Host "Version (ex: 0.2)"
if (-not $ver) { Write-Host "Aborted." -ForegroundColor Red; exit 1 }
# ── Bump the version in the single sources of truth ─────────────────────────────
$lastMsg = git log -1 --pretty=format:"%s"
if ($lastMsg -ne "chore: release v$ver") {
# Frontend (UI header + About popup)
(Get-Content frontend/src/version.ts) -replace "APP_VERSION = '.*'", "APP_VERSION = '$ver'" | Set-Content frontend/src/version.ts -Encoding utf8
# Backend (telemetry heartbeat version)
(Get-Content telemetry.go) -replace 'appVersion = ".*"', "appVersion = `"$ver`"" | Set-Content telemetry.go -Encoding utf8
git add frontend/src/version.ts telemetry.go
git commit -m "chore: release v$ver"
} else {
Write-Host "Release commit already exists, skipping version bump..." -ForegroundColor Yellow
}
git tag "v$ver" 2>$null
if ($LASTEXITCODE -ne 0) { Write-Host "Tag v$ver already exists locally, continuing..." -ForegroundColor Yellow }
# Push source to Gitea (origin) — source code stays on Gitea only
git push
if ($LASTEXITCODE -ne 0) { Write-Host "git push failed!" -ForegroundColor Red; exit 1 }
git push --tags
if ($LASTEXITCODE -ne 0) { Write-Host "git push --tags failed!" -ForegroundColor Red; exit 1 }
# ── Release notes from commits since the previous tag ───────────────────────────
$prevTag = git describe --tags --abbrev=0 "v$ver^" 2>$null
$changelog = if ($prevTag) {
git log "$prevTag..v$ver" --pretty=format:"- %s" --no-merges
} else {
git log "v$ver" --pretty=format:"- %s" --no-merges
}
$body = "## Changelog`n`n$($changelog -join "`n")"
Write-Host "`nRelease notes:`n$body`n" -ForegroundColor DarkGray
# ── Build the Windows exe (Wails compiles frontend + Go) ─────────────────────────
Write-Host "Building OpsLog.exe v$ver ..." -ForegroundColor Cyan
& $Wails build
if ($LASTEXITCODE -ne 0) { Write-Host "Build failed!" -ForegroundColor Red; exit 1 }
if (-not (Test-Path $ExePath)) { Write-Host "Built exe not found at $ExePath" -ForegroundColor Red; exit 1 }
# ── Gitea release — get existing or create new, then upload the exe ──────────────
$api = "https://$gitHost/api/v1/repos/$repo"
$headers = @{ Authorization = "token $token"; 'Content-Type' = 'application/json' }
try {
$release = Invoke-RestMethod "$api/releases/tags/v$ver" -Method GET -Headers $headers
Write-Host "Gitea: found existing release for v$ver (id=$($release.id)), uploading exe..." -ForegroundColor Yellow
} catch {
$payloadBytes = [System.Text.Encoding]::UTF8.GetBytes((@{ tag_name = "v$ver"; target_commitish = "main"; name = "OpsLog v$ver"; body = $body } | ConvertTo-Json))
try {
$release = Invoke-RestMethod "$api/releases" -Method POST -Headers $headers -Body $payloadBytes
} catch {
Write-Host "Gitea release creation failed: $_" -ForegroundColor Red; exit 1
}
}
$uploadUri = "https://$gitHost/api/v1/repos/$repo/releases/$($release.id)/assets?name=OpsLog.exe"
curl.exe -s -H "Authorization: token $token" -F "attachment=@$ExePath" $uploadUri | Out-Null
Write-Host "Gitea: release v$ver published." -ForegroundColor Green
# ── GitHub release (requires gh CLI: https://cli.github.com) ────────────────────
if (Get-Command gh -ErrorAction SilentlyContinue) {
Write-Host "Creating GitHub release v$ver ..." -ForegroundColor Cyan
$notesFile = [System.IO.Path]::GetTempFileName()
$body | Out-File -FilePath $notesFile -Encoding utf8
gh release create "v$ver" $ExePath `
--repo $GitHubRepo `
--title "OpsLog v$ver" `
--notes-file $notesFile
Remove-Item $notesFile
Write-Host "GitHub: release v$ver published." -ForegroundColor Green
} else {
Write-Host "gh CLI not found - skipping GitHub release (install from https://cli.github.com, then: gh auth login)" -ForegroundColor Yellow
}