diff --git a/scripts/create_release.ps1 b/scripts/create_release.ps1 index ee47729..fb8e9f5 100644 --- a/scripts/create_release.ps1 +++ b/scripts/create_release.ps1 @@ -8,7 +8,7 @@ if (-not $Token) { $Token = $env:GITEA_TOKEN if (-not $Token) { Write-Host "Fehler: Kein Token angegeben und GITEA_TOKEN Umgebungsvariable nicht gesetzt!" -ForegroundColor Red - Write-Host "Verwendung: .\create_release.ps1 -Token 'your_token' oder setze GITEA_TOKEN Umgebungsvariable" -ForegroundColor Yellow + Write-Host "Verwendung: .\create_release_simple.ps1 -Token 'your_token' oder setze GITEA_TOKEN Umgebungsvariable" -ForegroundColor Yellow Write-Host "Das Script führt automatisch einen Build durch und lädt alle Artefakte hoch." -ForegroundColor Cyan exit 1 } @@ -44,35 +44,34 @@ if ($lastTag -match "^v(\d+)\.(\d+)\.(\d+)(.*)$") { # Build durchführen Write-Host "Führe Build durch..." -ForegroundColor Yellow if (Test-Path "scripts\build_windows.bat") { - Write-Host "Verwende scripts\build_windows.bat..." -ForegroundColor Yellow cmd /c scripts\build_windows.bat + if ($LASTEXITCODE -ne 0) { + Write-Host "Build fehlgeschlagen!" -ForegroundColor Red + exit 1 + } } else { Write-Host "Fehler: scripts\build_windows.bat nicht gefunden!" -ForegroundColor Red exit 1 } -if ($LASTEXITCODE -ne 0) { - Write-Host "Build fehlgeschlagen!" -ForegroundColor Red - exit 1 -} + Write-Host "Build erfolgreich abgeschlossen!" -ForegroundColor Green -# Tests ausführen (Unit + optional Integration via PRIVATEBIN_IT) +# Tests ausführen Write-Host "Führe Tests aus..." -ForegroundColor Yellow if (Test-Path "build\CTestTestfile.cmake") { - pushd build | Out-Null + pushd build try { - # PRIVATEBIN_IT/PRIVATEBIN_SERVER werden ggf. aus der Umgebung übernommen ctest -C Release --output-on-failure if ($LASTEXITCODE -ne 0) { Write-Host "Tests fehlgeschlagen!" -ForegroundColor Red exit 1 } } finally { - popd | Out-Null + popd } Write-Host "Tests erfolgreich." -ForegroundColor Green } else { - Write-Host "Warnung: Keine Tests gefunden (build/CTestTestfile.cmake fehlt)." -ForegroundColor Yellow + Write-Host "Warnung: Keine Tests gefunden." -ForegroundColor Yellow } # Optional: clang-cl Coverage bauen und HTML-Report als Artefakt paketieren @@ -149,9 +148,39 @@ if ($status) { } # Remote/Repo-Infos ermitteln -$remoteUrl = git remote get-url origin 2>$null +Write-Host "Ermittle Git-Remote-Informationen..." -ForegroundColor Yellow + +# Versuche zuerst origin, dann upstream, dann den ersten verfügbaren Remote +$remoteUrl = $null +$remoteName = $null + +# Priorität: origin > upstream > erster verfügbarer +$preferredRemotes = @('origin', 'upstream') +foreach ($remote in $preferredRemotes) { + $url = git remote get-url $remote 2>$null + if ($url) { + $remoteUrl = $url + $remoteName = $remote + Write-Host "Verwende Remote '$remote': $url" -ForegroundColor Green + break + } +} + +# Falls keine bevorzugten Remotes gefunden wurden, nimm den ersten verfügbaren if (-not $remoteUrl) { - Write-Host "Fehler: Kein Git-Remote 'origin' gefunden." -ForegroundColor Red + $allRemotes = git remote 2>$null + if ($allRemotes) { + $firstRemote = $allRemotes[0] + $remoteUrl = git remote get-url $firstRemote 2>$null + $remoteName = $firstRemote + Write-Host "Verwende ersten verfügbaren Remote '$firstRemote': $remoteUrl" -ForegroundColor Yellow + } +} + +if (-not $remoteUrl) { + Write-Host "Fehler: Kein Git-Remote gefunden!" -ForegroundColor Red + Write-Host "Verfügbare Remotes:" -ForegroundColor Yellow + git remote -v 2>$null | ForEach-Object { Write-Host " $_" -ForegroundColor White } exit 1 } @@ -178,9 +207,16 @@ if ($path) { if (-not $gitHost -or -not $owner -or -not $repoName) { Write-Host "Fehler: Konnte Host/Owner/Repo aus Remote-URL nicht ermitteln: $remoteUrl" -ForegroundColor Red + Write-Host "Erwartetes Format: https://host/owner/repo oder git@host:owner/repo" -ForegroundColor Yellow exit 1 } +Write-Host "Git-Info extrahiert:" -ForegroundColor Green +Write-Host " Host: $gitHost" -ForegroundColor White +Write-Host " Owner: $owner" -ForegroundColor White +Write-Host " Repository: $repoName" -ForegroundColor White +Write-Host " Remote: $remoteName" -ForegroundColor White + # Tag erstellen und pushen git tag -a $newVersion -m "Release $newVersion" if ($LASTEXITCODE -ne 0) { @@ -188,7 +224,7 @@ if ($LASTEXITCODE -ne 0) { exit 1 } -git push origin $newVersion +git push $remoteName $newVersion if ($LASTEXITCODE -ne 0) { Write-Host "Tag-Push fehlgeschlagen. Stelle sicher, dass Du Push-Rechte besitzt." -ForegroundColor Red exit 1 @@ -282,4 +318,4 @@ if (Test-Path $distPath) { Write-Host "dist-Ordner nicht gefunden!" -ForegroundColor Yellow } -Write-Host "Release-Erstellung abgeschlossen!" -ForegroundColor Green \ No newline at end of file +Write-Host "Release-Erstellung erfolgreich abgeschlossen!" -ForegroundColor Green diff --git a/scripts/create_release_simple.ps1 b/scripts/create_release_simple.ps1 deleted file mode 100644 index 46b4739..0000000 --- a/scripts/create_release_simple.ps1 +++ /dev/null @@ -1,284 +0,0 @@ -param( - [Parameter(Mandatory=$false)] - [string]$Token -) - -# Token aus Umgebungsvariable laden falls nicht als Parameter übergeben -if (-not $Token) { - $Token = $env:GITEA_TOKEN - if (-not $Token) { - Write-Host "Fehler: Kein Token angegeben und GITEA_TOKEN Umgebungsvariable nicht gesetzt!" -ForegroundColor Red - Write-Host "Verwendung: .\create_release_simple.ps1 -Token 'your_token' oder setze GITEA_TOKEN Umgebungsvariable" -ForegroundColor Yellow - Write-Host "Das Script führt automatisch einen Build durch und lädt alle Artefakte hoch." -ForegroundColor Cyan - exit 1 - } - Write-Host "Token aus Umgebungsvariable GITEA_TOKEN geladen" -ForegroundColor Green -} - -Write-Host "=== lib-privatebin Release Creator ===" -ForegroundColor Cyan - -# Aktuelle Version ermitteln -$lastTag = git describe --tags --abbrev=0 2>$null -if (-not $lastTag) { - $lastTag = "v0.1.0" -} - -Write-Host "Letzter Tag: $lastTag" -ForegroundColor Green - -# Version parsen -if ($lastTag -match "^v(\d+)\.(\d+)\.(\d+)(.*)$") { - $major = [int]$matches[1] - $minor = [int]$matches[2] - $patch = [int]$matches[3] - $suffix = $matches[4] - - $newPatch = $patch + 1 - $newVersion = "v$major.$minor.$newPatch$suffix" - - Write-Host "Neue Version: $newVersion" -ForegroundColor Green -} else { - Write-Host "Fehler: Ungültiges Versionsformat: $lastTag" -ForegroundColor Red - exit 1 -} - -# Build durchführen -Write-Host "Führe Build durch..." -ForegroundColor Yellow -if (Test-Path "scripts\build_windows.bat") { - cmd /c scripts\build_windows.bat - if ($LASTEXITCODE -ne 0) { - Write-Host "Build fehlgeschlagen!" -ForegroundColor Red - exit 1 - } -} else { - Write-Host "Fehler: scripts\build_windows.bat nicht gefunden!" -ForegroundColor Red - exit 1 -} - -Write-Host "Build erfolgreich abgeschlossen!" -ForegroundColor Green - -# Tests ausführen -Write-Host "Führe Tests aus..." -ForegroundColor Yellow -if (Test-Path "build\CTestTestfile.cmake") { - pushd build - try { - ctest -C Release --output-on-failure - if ($LASTEXITCODE -ne 0) { - Write-Host "Tests fehlgeschlagen!" -ForegroundColor Red - exit 1 - } - } finally { - popd - } - Write-Host "Tests erfolgreich." -ForegroundColor Green -} else { - Write-Host "Warnung: Keine Tests gefunden." -ForegroundColor Yellow -} - -# Optional: clang-cl Coverage bauen und HTML-Report als Artefakt paketieren -Write-Host "Erzeuge optionalen Coverage-Report (clang-cl + LLVM), falls Tools vorhanden sind..." -ForegroundColor Yellow -try { - $llvmCov = "C:\Program Files\LLVM\bin\llvm-cov.exe" - $llvmProf = "C:\Program Files\LLVM\bin\llvm-profdata.exe" - $llvmCovExists = Test-Path $llvmCov - $llvmProfExists = Test-Path $llvmProf - - if ($llvmCovExists -and $llvmProfExists) { - $toolchain = Join-Path $env:USERPROFILE 'vcpkg\scripts\buildsystems\vcpkg.cmake' - $haveToolchain = Test-Path $toolchain - - $cmakeArgs = @( - '-S','.', - '-B','build-clang', - '-G','Visual Studio 17 2022', - '-A','x64', - '-T','ClangCL', - '-DENABLE_LLVM_COVERAGE=ON', - ("-DLLVM_PROFDATA={0}" -f $llvmProf), - ("-DLLVM_COV={0}" -f $llvmCov) - ) - - if ($haveToolchain) { - $cmakeArgs += ("-DCMAKE_TOOLCHAIN_FILE={0}" -f $toolchain) - $cmakeArgs += '-DVCPKG_TARGET_TRIPLET=x64-windows' - } - - & cmake @cmakeArgs | Out-Null - if ($LASTEXITCODE -ne 0) { - throw "CMake-Konfiguration für Coverage fehlgeschlagen" - } - - # Run coverage target with integration tests disabled to avoid rate limits - $env:PRIVATEBIN_IT = '0' - & cmake --build build-clang --config Release --target coverage_llvm - if ($LASTEXITCODE -ne 0) { - throw "Coverage-Build fehlgeschlagen" - } - - $htmlDir = "build-clang\coverage\html" - if (Test-Path $htmlDir) { - if (-not (Test-Path 'dist')) { - New-Item -ItemType Directory -Path 'dist' | Out-Null - } - $zipPath = "dist\coverage_html.zip" - if (Test-Path $zipPath) { - Remove-Item -Force $zipPath - } - Compress-Archive -Path "$htmlDir\*" -DestinationPath $zipPath - Write-Host "Coverage-HTML nach $zipPath gepackt." -ForegroundColor Green - } else { - Write-Host "Hinweis: Kein Coverage-HTML-Verzeichnis gefunden (Tests evtl. ohne Ausführungspfad)." -ForegroundColor Yellow - } - } else { - Write-Host "LLVM-Tools nicht gefunden; überspringe Coverage (erwartet: $llvmCov / $llvmProf)." -ForegroundColor Yellow - } -} catch { - Write-Host "Warnung: Coverage-Erzeugung fehlgeschlagen: $($_.Exception.Message)" -ForegroundColor Yellow -} - -# Commit & Push, Tag & Push -# Änderungen committen -$status = git status --porcelain -if ($status) { - git add -A - git commit -m "Release $newVersion prepare for release" - if ($LASTEXITCODE -ne 0) { - Write-Host "Commit fehlgeschlagen." -ForegroundColor Red - exit 1 - } -} - -# Remote/Repo-Infos ermitteln -$remoteUrl = git remote get-url origin 2>$null -if (-not $remoteUrl) { - Write-Host "Fehler: Kein Git-Remote 'origin' gefunden." -ForegroundColor Red - exit 1 -} - -# Host, Owner, Repo aus URL extrahieren (https oder ssh) -$gitHost = $null -$owner = $null -$repoName = $null - -if ($remoteUrl -match '^(https?://)([^/]+)/(.+?)(?:\.git)?$') { - $gitHost = $matches[2] - $path = $matches[3] -} elseif ($remoteUrl -match '^[^@]+@([^:]+):(.+?)(?:\.git)?$') { - $gitHost = $matches[1] - $path = $matches[2] -} - -if ($path) { - $parts = $path.Split('/') - if ($parts.Length -ge 2) { - $owner = $parts[$parts.Length-2] - $repoName = $parts[$parts.Length-1] - } -} - -if (-not $gitHost -or -not $owner -or -not $repoName) { - Write-Host "Fehler: Konnte Host/Owner/Repo aus Remote-URL nicht ermitteln: $remoteUrl" -ForegroundColor Red - exit 1 -} - -# Tag erstellen und pushen -git tag -a $newVersion -m "Release $newVersion" -if ($LASTEXITCODE -ne 0) { - Write-Host "Tag-Erstellung fehlgeschlagen." -ForegroundColor Red - exit 1 -} - -git push origin $newVersion -if ($LASTEXITCODE -ne 0) { - Write-Host "Tag-Push fehlgeschlagen. Stelle sicher, dass Du Push-Rechte besitzt." -ForegroundColor Red - exit 1 -} - -# Vor Upload: Artefakte einsammeln (dist) -if (Test-Path "scripts\collect_binaries.ps1") { - Write-Host "Sammle Build-Artefakte (scripts/collect_binaries.ps1)..." -ForegroundColor Yellow - powershell -NoProfile -ExecutionPolicy Bypass -File scripts\collect_binaries.ps1 -} - -# Release erstellen -$releaseBody = "## What is New in $newVersion`n`n- AUTOMATED: Release created by script`n- VERSION: Bumped from $lastTag to $newVersion`n- BUILD: Automatic build with build_windows.bat`n`n## Build Artifacts`n`nBuild-Artefakte werden automatisch hochgeladen und hier angezeigt.`n`nTypische Artefakte:`n- privatebinapi.dll - Windows Dynamic Link Library`n- privatebinapi.lib - Windows Import Library`n- example.exe - Combined example program`n- privatebinapi.h - C++ header file" - -$releaseData = @{ - tag_name = $newVersion - name = "$newVersion - Automated Release" - body = $releaseBody - draft = $false - prerelease = $false -} | ConvertTo-Json -Depth 10 - -$headers = @{ - "Authorization" = "token $Token" - "Content-Type" = "application/json" -} - -$releaseUri = "https://$gitHost/api/v1/repos/$owner/$repoName/releases" - -try { - $release = Invoke-RestMethod -Uri $releaseUri -Method Post -Headers $headers -Body $releaseData -ErrorAction Stop -} catch { - Write-Host "Fehler beim Erstellen des Releases: $($_.Exception.Message)" -ForegroundColor Red - exit 1 -} - -Write-Host "Release erstellt: $($release.id)" -ForegroundColor Green -Write-Host "URL: $($release.html_url)" -ForegroundColor Green - -# Build-Artefakte zum Release hinzufügen -Write-Host "Füge Build-Artefakte hinzu..." -ForegroundColor Yellow - -# Artefakte aus dem dist-Ordner finden -$distPath = "dist" -if (Test-Path $distPath) { - $artifacts = Get-ChildItem -Path $distPath -Recurse -File | Where-Object { - $_.Extension -match "\.(dll|lib|exe|h|zip)$" - } - - if ($artifacts) { - Write-Host "Gefundene Artefakte:" -ForegroundColor Green - foreach ($artifact in $artifacts) { - Write-Host " - $($artifact.Name)" -ForegroundColor White - } - - # Artefakte hochladen - foreach ($artifact in $artifacts) { - Write-Host "Lade hoch: $($artifact.Name)..." -ForegroundColor Yellow - - $uploadUri = "https://$gitHost/api/v1/repos/$owner/$repoName/releases/$($release.id)/assets" - - $boundary = [System.Guid]::NewGuid().ToString() - $LF = "`r`n" - $bodyLines = @( - "--$boundary", - "Content-Disposition: form-data; name=`"attachment`"; filename=`"$($artifact.Name)`"", - "Content-Type: application/octet-stream", - "", - [System.IO.File]::ReadAllBytes($artifact.FullName), - "--$boundary--" - ) - - $body = $bodyLines -join $LF - - $uploadHeaders = @{ - "Authorization" = "token $Token" - "Content-Type" = "multipart/form-data; boundary=$boundary" - } - - try { - $uploadResponse = Invoke-RestMethod -Uri $uploadUri -Method Post -Headers $uploadHeaders -Body $body - Write-Host " ✓ $($artifact.Name) erfolgreich hochgeladen" -ForegroundColor Green - } catch { - Write-Host " ✗ Fehler beim Hochladen von $($artifact.Name): $($_.Exception.Message)" -ForegroundColor Red - } - } - } else { - Write-Host "Keine Build-Artefakte im dist-Ordner gefunden!" -ForegroundColor Yellow - } -} else { - Write-Host "dist-Ordner nicht gefunden!" -ForegroundColor Yellow -} - -Write-Host "Release-Erstellung erfolgreich abgeschlossen!" -ForegroundColor Green