Files
pyramid/scripts/release.ps1
T
Bernd Steckmeister d706ace35f chore: add automated release script for Windows + Android
scripts/release.ps1 reads version from pubspec.yaml, builds both platforms,
creates a Gitea release with auto-generated changelog, and uploads artifacts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-28 21:54:27 +02:00

119 lines
6.1 KiB
PowerShell

# Pyramid Release Script
# Usage: .\scripts\release.ps1
# Builds Windows + Android, creates Gitea release, uploads artifacts.
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# ── Config ────────────────────────────────────────────────────────────────────
$GiteaBase = "https://git.steggi-matrix.work"
$GiteaRepo = "steggi/pyramid"
$GiteaToken = "bb522f9646c6856c9ab58bef0151ac36a9ce1d57"
$Headers = @{ Authorization = "token $GiteaToken"; "Content-Type" = "application/json" }
# ── Read version from pubspec.yaml ────────────────────────────────────────────
$pubspec = Get-Content "pubspec.yaml" | Where-Object { $_ -match "^version:" }
if (-not $pubspec) { Write-Error "version not found in pubspec.yaml"; exit 1 }
$version = ($pubspec -split ":")[1].Trim().Split("+")[0]
$tag = "v$version"
Write-Host ""
Write-Host " Pyramid Release Builder" -ForegroundColor Cyan
Write-Host " Version : $tag" -ForegroundColor White
Write-Host ""
# ── Check for existing release ────────────────────────────────────────────────
try {
$existing = Invoke-RestMethod "$GiteaBase/api/v1/repos/$GiteaRepo/releases/tags/$tag" `
-Headers $Headers -Method Get -ErrorAction Stop
Write-Host " [!] Release $tag existiert bereits auf Gitea." -ForegroundColor Yellow
$overwrite = Read-Host " Überschreiben? (j/N)"
if ($overwrite -notmatch "^[jJ]$") { Write-Host " Abgebrochen."; exit 0 }
# Delete existing release
Invoke-RestMethod "$GiteaBase/api/v1/repos/$GiteaRepo/releases/$($existing.id)" `
-Headers $Headers -Method Delete | Out-Null
Write-Host " Alter Release gelöscht." -ForegroundColor Gray
} catch {
# 404 = release doesn't exist, that's fine
}
# ── Release notes ─────────────────────────────────────────────────────────────
Write-Host " Release-Notizen (leer lassen = Changelog aus Git-Commits):" -ForegroundColor Cyan
$notes = Read-Host " > "
if ([string]::IsNullOrWhiteSpace($notes)) {
# Auto-generate from git log since last tag
$lastTag = git describe --tags --abbrev=0 HEAD^ 2>$null
if ($lastTag) {
$notes = git log "$lastTag..HEAD" --pretty=format:"- %s" 2>$null | Out-String
} else {
$notes = git log --pretty=format:"- %s" -20 2>$null | Out-String
}
Write-Host " (Commits als Release-Notizen verwendet)" -ForegroundColor Gray
}
# ── Build Windows ─────────────────────────────────────────────────────────────
Write-Host ""
Write-Host " [1/4] Windows Build..." -ForegroundColor Cyan
flutter build windows --release
if ($LASTEXITCODE -ne 0) { Write-Error "Windows build fehlgeschlagen"; exit 1 }
$winSrc = "build\windows\x64\runner\Release"
$winZip = "build\pyramid-windows-$tag.zip"
if (Test-Path $winZip) { Remove-Item $winZip -Force }
Compress-Archive -Path "$winSrc\*" -DestinationPath $winZip
Write-Host " Windows ZIP: $winZip" -ForegroundColor Green
# ── Build Android ─────────────────────────────────────────────────────────────
Write-Host ""
Write-Host " [2/4] Android Build..." -ForegroundColor Cyan
flutter build apk --release
if ($LASTEXITCODE -ne 0) { Write-Error "Android build fehlgeschlagen"; exit 1 }
$apkSrc = "build\app\outputs\flutter-apk\app-release.apk"
$apkDst = "build\pyramid-android-$tag.apk"
Copy-Item $apkSrc $apkDst -Force
Write-Host " Android APK: $apkDst" -ForegroundColor Green
# ── Git tag ───────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host " [3/4] Git Tag $tag..." -ForegroundColor Cyan
git tag -f $tag
git push origin $tag --force
Write-Host " Tag gepusht." -ForegroundColor Green
# ── Create Gitea release ──────────────────────────────────────────────────────
Write-Host ""
Write-Host " [4/4] Gitea Release erstellen..." -ForegroundColor Cyan
$body = @{
tag_name = $tag
name = "Pyramid $tag"
body = $notes.Trim()
draft = $false
prerelease = $false
target_commitish = "master"
} | ConvertTo-Json -Compress
$release = Invoke-RestMethod "$GiteaBase/api/v1/repos/$GiteaRepo/releases" `
-Headers $Headers -Method Post -Body $body
$releaseId = $release.id
Write-Host " Release ID: $releaseId" -ForegroundColor Gray
# ── Upload artifacts ──────────────────────────────────────────────────────────
function Upload-Asset($filePath, $fileName) {
$uploadHeaders = @{ Authorization = "token $GiteaToken" }
$form = @{ attachment = Get-Item $filePath }
$uri = "$GiteaBase/api/v1/repos/$GiteaRepo/releases/$releaseId/assets?name=$fileName"
Invoke-RestMethod $uri -Headers $uploadHeaders -Method Post -Form $form | Out-Null
Write-Host " Hochgeladen: $fileName" -ForegroundColor Green
}
Upload-Asset $winZip "pyramid-windows-$tag.zip"
Upload-Asset $apkDst "pyramid-android-$tag.apk"
# ── Done ──────────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host " Release $tag erfolgreich erstellt!" -ForegroundColor Green
Write-Host " $GiteaBase/$GiteaRepo/releases/tag/$tag" -ForegroundColor Cyan
Write-Host ""