HomeStream/publish.ps1

109 lines
4.6 KiB
PowerShell
Raw Normal View History

2026-05-10 23:46:12 +02:00
# HomeStream Release-Build und Upload zu Forgejo
# Verwendung:
# .\publish.ps1 # baut + zippt
# .\publish.ps1 -Tag v1.0.0 # taggt + baut + zippt + erstellt Release auf Forgejo
#
# Token wird aus Umgebungsvariable HOMESTREAM_TOKEN gelesen, ansonsten aus dem
# Default-Token unten (gleicher Token wie MailPrint).
param(
[string]$Tag = '',
[string]$Token = $env:HOMESTREAM_TOKEN
)
if (-not $Token) {
$Token = '63f650934f69d5684cb556a9a9e7d8e65495e257'
}
$ErrorActionPreference = 'Stop'
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$RepoUser = 'dimedtec'
$RepoName = 'HomeStream'
$ApiBase = "https://www.dimedtec.net/api/v1/repos/$RepoUser/$RepoName"
# ── 1. Tag setzen falls angegeben ─────────────────────────────────────────
if ($Tag) {
if ($Tag -notmatch '^v\d+\.\d+\.\d+') {
throw "Tag muss Format v1.2.3 haben"
}
Write-Host "→ Tag $Tag setzen..."
# Git schreibt Status auf stderr; mit try-catch abfangen damit PS nicht abbricht.
# Tag existiert evtl. schon — das ist OK, wir ignorieren den Fehler.
try { git -C $ScriptDir tag $Tag 2>$null | Out-Null } catch { }
try { git -C $ScriptDir push origin $Tag 2>$null | Out-Null } catch { }
2026-05-10 23:46:12 +02:00
Write-Host " OK"
}
# Aktuelle Version aus Git-Tag bestimmen
$currentTag = $null
try { $currentTag = (git -C $ScriptDir describe --tags --abbrev=0 2>$null) } catch { }
if (-not $currentTag) { $currentTag = 'v0.1.0' }
$version = $currentTag -replace '^v',''
# ── 2. Publish ────────────────────────────────────────────────────────────
$PublishDir = Join-Path $ScriptDir 'publish'
if (Test-Path $PublishDir) { Remove-Item -Recurse -Force $PublishDir }
Write-Host "→ Publish (self-contained, single-file, win-x64)..."
dotnet publish $ScriptDir\HomeStream.csproj `
-c Release `
-r win-x64 `
--self-contained true `
-p:PublishSingleFile=true `
-p:IncludeNativeLibrariesForSelfExtract=true `
-p:DebugType=None `
-p:DebugSymbols=false `
-o $PublishDir
if ($LASTEXITCODE -ne 0) { throw "Publish fehlgeschlagen" }
# Aufräumen: PDBs raus
Get-ChildItem $PublishDir -Filter *.pdb -Recurse | Remove-Item -Force
$exeSize = [math]::Round((Get-Item "$PublishDir\HomeStream.exe").Length / 1MB, 1)
Write-Host " HomeStream.exe: $exeSize MB"
# ── 3. ZIP packen ─────────────────────────────────────────────────────────
$ZipPath = Join-Path $ScriptDir "HomeStream-$version-win-x64.zip"
if (Test-Path $ZipPath) { Remove-Item $ZipPath }
Compress-Archive -Path "$PublishDir\*" -DestinationPath $ZipPath -CompressionLevel Optimal
$zipSize = [math]::Round((Get-Item $ZipPath).Length / 1MB, 1)
Write-Host "→ ZIP: $ZipPath ($zipSize MB)"
# ── 4. Release auf Forgejo erstellen (nur bei explizitem Tag) ─────────────
if (-not $Tag) {
Write-Host "`nFertig. Zum Veröffentlichen: .\publish.ps1 -Tag v$version"
exit 0
}
Write-Host "→ Forgejo-Release $Tag erstellen..."
$headers = @{ 'Authorization' = "token $Token"; 'Content-Type' = 'application/json; charset=utf-8' }
$bodyObj = @{
2026-05-10 23:46:12 +02:00
tag_name = $Tag
name = "HomeStream $version"
body = "Self-contained Release fuer Windows 10/11 (x64). Keine .NET-Installation noetig."
2026-05-10 23:46:12 +02:00
draft = $false
prerelease = $false
}
# Explizit UTF-8 kodieren damit Umlaute korrekt uebertragen werden
$bodyBytes = [System.Text.Encoding]::UTF8.GetBytes(($bodyObj | ConvertTo-Json))
$release = Invoke-RestMethod -Uri "$ApiBase/releases" -Method Post -Headers $headers -Body $bodyBytes
2026-05-10 23:46:12 +02:00
Write-Host " Release-ID: $($release.id)"
# ── 5. ZIP als Asset hochladen ────────────────────────────────────────────
Write-Host "→ ZIP hochladen..."
$uploadUrl = "$ApiBase/releases/$($release.id)/assets?name=" + [uri]::EscapeDataString((Split-Path $ZipPath -Leaf))
$bytes = [System.IO.File]::ReadAllBytes($ZipPath)
# Multipart form upload via curl (PowerShell Invoke-WebRequest hat Issues mit grossen Files)
& curl.exe -X POST `
-H "Authorization: token $Token" `
-F "attachment=@$ZipPath" `
"$ApiBase/releases/$($release.id)/assets?name=$(Split-Path $ZipPath -Leaf)" `
--silent --show-error --output - | Out-Null
if ($LASTEXITCODE -ne 0) { throw "Upload fehlgeschlagen" }
Write-Host "`n✅ Release veröffentlicht:"
Write-Host " $($release.html_url)"