From 7fe19b90ee78e49151e04ddb6406db97703d3b0d Mon Sep 17 00:00:00 2001 From: administrator Date: Sun, 10 May 2026 23:46:12 +0200 Subject: [PATCH] publish.ps1 + gitignore Hilfsskripte --- .gitignore | 2 + publish.ps1 | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 publish.ps1 diff --git a/.gitignore b/.gitignore index 0625409..e4e5532 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ logs/ # Temp *.tmp *.temp +response.json +_*.ps1 # OS Thumbs.db diff --git a/publish.ps1 b/publish.ps1 new file mode 100644 index 0000000..8da35d0 --- /dev/null +++ b/publish.ps1 @@ -0,0 +1,105 @@ +# 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 -C $ScriptDir tag $Tag 2>&1 | Out-Null + git -C $ScriptDir push origin $Tag 2>&1 | Out-Null + 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' } +$body = @{ + tag_name = $Tag + name = "HomeStream $version" + body = "Self-contained Release für Windows 10/11 (x64). Keine .NET-Installation nötig." + draft = $false + prerelease = $false +} | ConvertTo-Json + +$release = Invoke-RestMethod -Uri "$ApiBase/releases" -Method Post -Headers $headers -Body $body +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)"