77 lines
2.8 KiB
PowerShell
77 lines
2.8 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[ValidatePattern("^\d+\.\d+\.\d+$")]
|
|
[string]$Version,
|
|
|
|
[string]$Notes = "Stabiles SyncVito-Release"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
Set-Location -LiteralPath $ProjectRoot
|
|
|
|
if (-not $env:GITEA_TOKEN) {
|
|
throw "GITEA_TOKEN ist nicht gesetzt. Das Token nur lokal als Umgebungsvariable hinterlegen."
|
|
}
|
|
|
|
$ConfiguredVersion = python -c "import sys; sys.path.insert(0, 'src'); from syncvito.version import __version__; print(__version__)"
|
|
if ($ConfiguredVersion.Trim() -ne $Version) {
|
|
throw "Die angeforderte Version $Version stimmt nicht mit syncvito.version ($ConfiguredVersion) überein."
|
|
}
|
|
|
|
& (Join-Path $ProjectRoot "build.ps1")
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "Der Build ist fehlgeschlagen."
|
|
}
|
|
|
|
$Tag = "v$Version"
|
|
git rev-parse --verify $Tag 2>$null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
git tag -a $Tag -m "SyncVito $Version"
|
|
}
|
|
git push origin main
|
|
git push origin $Tag
|
|
|
|
$Headers = @{ Authorization = "token $env:GITEA_TOKEN" }
|
|
$ApiBase = "https://gitea.davito.synology.me/api/v1/repos/Davito/SyncVito"
|
|
$Payload = @{
|
|
tag_name = $Tag
|
|
target_commitish = "main"
|
|
name = "SyncVito $Version"
|
|
body = $Notes
|
|
draft = $false
|
|
prerelease = $false
|
|
} | ConvertTo-Json
|
|
|
|
$Release = Invoke-RestMethod -Uri "$ApiBase/releases" -Method Post -Headers $Headers -ContentType "application/json" -Body $Payload
|
|
|
|
Add-Type -AssemblyName System.Net.Http
|
|
$Client = [System.Net.Http.HttpClient]::new()
|
|
$Client.DefaultRequestHeaders.Authorization = [System.Net.Http.Headers.AuthenticationHeaderValue]::new("token", $env:GITEA_TOKEN)
|
|
try {
|
|
foreach ($FilePath in @("dist\SyncVito.exe", "dist\SyncVito.exe.sha256")) {
|
|
$AbsolutePath = Join-Path $ProjectRoot $FilePath
|
|
$FileName = Split-Path -Leaf $AbsolutePath
|
|
$Form = [System.Net.Http.MultipartFormDataContent]::new()
|
|
try {
|
|
$Bytes = [System.IO.File]::ReadAllBytes($AbsolutePath)
|
|
$Content = [System.Net.Http.ByteArrayContent]::new($Bytes)
|
|
$Content.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::new("application/octet-stream")
|
|
$Form.Add($Content, "attachment", $FileName)
|
|
$UploadUrl = "$ApiBase/releases/$($Release.id)/assets?name=$([uri]::EscapeDataString($FileName))"
|
|
$Response = $Client.PostAsync($UploadUrl, $Form).GetAwaiter().GetResult()
|
|
if (-not $Response.IsSuccessStatusCode) {
|
|
throw "Upload von $FileName fehlgeschlagen: $($Response.StatusCode) $($Response.Content.ReadAsStringAsync().Result)"
|
|
}
|
|
}
|
|
finally {
|
|
$Form.Dispose()
|
|
}
|
|
}
|
|
}
|
|
finally {
|
|
$Client.Dispose()
|
|
}
|
|
|
|
Write-Host "Release $Tag wurde veröffentlicht: https://gitea.davito.synology.me/Davito/SyncVito/releases"
|