feat: Implement brand-aware release creation for Agravity
Some checks failed
Tests & Quality Checks / Test on Python 3.11 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.11-1 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12-1 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.10 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.11-2 (push) Has been cancelled
Tests & Quality Checks / Test on Python 3.12-2 (push) Has been cancelled
Tests & Quality Checks / Build Artifacts (push) Has been cancelled
Tests & Quality Checks / Build Artifacts-1 (push) Has been cancelled

- Added support for multiple brands in release scripts, allowing for branded artifacts.
- Introduced brand configuration management with JSON files for each brand.
- Created a new `brand_config.py` script to handle brand-specific logic and asset resolution.
- Updated `create_release.ps1` and `create_release.sh` scripts to utilize brand configurations and generate release manifests.
- Added unit tests for brand configuration loading and release manifest generation.
- Introduced `agravity` brand with its specific configuration in `agravity.json`.
This commit is contained in:
claudi 2026-03-10 16:18:28 +01:00
parent b988532aaa
commit fd69996c53
8 changed files with 552 additions and 409 deletions

View file

@ -1,70 +1,36 @@
# Create Forgejo Release with Binary Assets
# Usage: .\create_release.ps1 [-Version 1.0.0]
# If -Version is not provided, it will be read from src/webdrop_bridge/__init__.py
# Uses your Forgejo credentials (same as git)
# First run will prompt for credentials and save them to this session
param(
[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[string]$Version,
[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[string[]]$Brands = @("agravity"),
[Parameter(Mandatory = $false)]
[string]$ForgejoUser,
[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[string]$ForgejoPW,
[switch]$ClearCredentials,
[switch]$SkipExe,
[string]$ForgejoUrl = "https://git.him-tools.de",
[string]$Repo = "HIM-public/webdrop-bridge",
[string]$ExePath = "build\dist\windows\WebDropBridge\WebDropBridge.exe",
[string]$ChecksumPath = "build\dist\windows\WebDropBridge\WebDropBridge.exe.sha256"
[string]$Repo = "HIM-public/webdrop-bridge"
)
$ErrorActionPreference = "Stop"
# Get project root (PSScriptRoot is build/scripts, go up to project root with ..\..)
$projectRoot = Resolve-Path (Join-Path $PSScriptRoot "..\..")
# Resolve file paths relative to project root
$ExePath = Join-Path $projectRoot $ExePath
$ChecksumPath = Join-Path $projectRoot $ChecksumPath
$MsiPath = Join-Path $projectRoot $MsiPath
# Function to read version from .env or .env.example
function Get-VersionFromEnv {
# Use already resolved project root
# Try .env first (runtime config), then .env.example (template)
$envFile = Join-Path $projectRoot ".env"
$envExampleFile = Join-Path $projectRoot ".env.example"
# Check .env first
if (Test-Path $envFile) {
$content = Get-Content $envFile -Raw
if ($content -match 'APP_VERSION=([^\r\n]+)') {
Write-Host "Version read from .env" -ForegroundColor Gray
return $matches[1].Trim()
}
}
# Fall back to .env.example
if (Test-Path $envExampleFile) {
$content = Get-Content $envExampleFile -Raw
if ($content -match 'APP_VERSION=([^\r\n]+)') {
Write-Host "Version read from .env.example" -ForegroundColor Gray
return $matches[1].Trim()
}
}
Write-Host "ERROR: Could not find APP_VERSION in .env or .env.example" -ForegroundColor Red
exit 1
$pythonExe = Join-Path $projectRoot ".venv\Scripts\python.exe"
if (-not (Test-Path $pythonExe)) {
$pythonExe = "python"
}
$brandHelper = Join-Path $projectRoot "build\scripts\brand_config.py"
$manifestOutput = Join-Path $projectRoot "build\dist\release-manifest.json"
function Get-CurrentVersion {
return (& $pythonExe -c "from pathlib import Path; import sys; sys.path.insert(0, str(Path(r'$projectRoot/build/scripts').resolve())); from version_utils import get_current_version; print(get_current_version())").Trim()
}
# Handle --ClearCredentials flag
if ($ClearCredentials) {
Remove-Item env:FORGEJO_USER -ErrorAction SilentlyContinue
Remove-Item env:FORGEJO_PASS -ErrorAction SilentlyContinue
@ -72,190 +38,95 @@ if ($ClearCredentials) {
exit 0
}
# Get credentials from sources (in order of priority)
if (-not $ForgejoUser) {
$ForgejoUser = $env:FORGEJO_USER
}
if (-not $ForgejoPW) {
$ForgejoPW = $env:FORGEJO_PASS
}
# If still no credentials, prompt user interactively
if (-not $ForgejoUser -or -not $ForgejoPW) {
Write-Host "Forgejo credentials not found. Enter your credentials:" -ForegroundColor Yellow
if (-not $ForgejoUser) {
$ForgejoUser = Read-Host "Username"
}
if (-not $ForgejoPW) {
$securePass = Read-Host "Password" -AsSecureString
$ForgejoPW = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($securePass))
}
# Save credentials to environment for this session
$env:FORGEJO_USER = $ForgejoUser
$env:FORGEJO_PASS = $ForgejoPW
Write-Host "[OK] Credentials saved to this PowerShell session" -ForegroundColor Green
Write-Host "Tip: Credentials will persist until you close PowerShell or run: .\create_release.ps1 -ClearCredentials" -ForegroundColor Gray
}
# Verify Version parameter - if not provided, read from .env.example
if (-not $Version) {
Write-Host "Version not provided, reading from .env.example..." -ForegroundColor Cyan
$Version = Get-VersionFromEnv
Write-Host "Using version: $Version" -ForegroundColor Green
$Version = Get-CurrentVersion
}
# Define MSI path with resolved version
$MsiPath = Join-Path $projectRoot "build\dist\windows\WebDropBridge-$Version-Setup.msi"
$artifactPaths = New-Object System.Collections.Generic.List[string]
foreach ($brand in $Brands) {
$brandJson = & $pythonExe $brandHelper show --brand $brand | ConvertFrom-Json
$msiPath = Join-Path $projectRoot "build\dist\windows\$($brandJson.brand_id)\$($brandJson.asset_prefix)-$Version-win-x64.msi"
$checksumPath = "$msiPath.sha256"
# Verify files exist (exe/checksum optional, MSI required)
if (-not $SkipExe) {
if (-not (Test-Path $ExePath)) {
Write-Host "WARNING: Executable not found at $ExePath" -ForegroundColor Yellow
Write-Host " Use -SkipExe flag to skip exe upload" -ForegroundColor Gray
$SkipExe = $true
}
if (-not $SkipExe -and -not (Test-Path $ChecksumPath)) {
Write-Host "WARNING: Checksum file not found at $ChecksumPath" -ForegroundColor Yellow
Write-Host " Exe will not be uploaded" -ForegroundColor Gray
$SkipExe = $true
if (Test-Path $msiPath) {
$artifactPaths.Add($msiPath)
if (Test-Path $checksumPath) {
$artifactPaths.Add($checksumPath)
}
$msiSize = (Get-Item $msiPath).Length / 1MB
Write-Host "Windows artifact: $([System.IO.Path]::GetFileName($msiPath)) ($([math]::Round($msiSize, 2)) MB)"
}
}
# MSI is the primary release artifact
if (-not (Test-Path $MsiPath)) {
Write-Host "ERROR: MSI installer not found at $MsiPath" -ForegroundColor Red
Write-Host "Please build with MSI support:" -ForegroundColor Yellow
Write-Host " python build\scripts\build_windows.py --msi" -ForegroundColor Cyan
& $pythonExe $brandHelper release-manifest --version $Version --output $manifestOutput --brands $Brands | Out-Null
if (Test-Path $manifestOutput) {
$artifactPaths.Add($manifestOutput)
}
if ($artifactPaths.Count -eq 0) {
Write-Host "ERROR: No Windows artifacts found for the requested brands" -ForegroundColor Red
exit 1
}
Write-Host "Creating WebDropBridge $Version release on Forgejo..." -ForegroundColor Cyan
# Get file info
$msiSize = (Get-Item $MsiPath).Length / 1MB
Write-Host "Primary Artifact: WebDropBridge-$Version-Setup.msi ($([math]::Round($msiSize, 2)) MB)"
if (-not $SkipExe) {
$exeSize = (Get-Item $ExePath).Length / 1MB
$checksum = Get-Content $ChecksumPath -Raw
Write-Host "Optional Artifact: WebDropBridge.exe ($([math]::Round($exeSize, 2)) MB)"
Write-Host " Checksum: $($checksum.Substring(0, 16))..."
}
# Create basic auth header
$auth = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${ForgejoUser}:${ForgejoPW}"))
$headers = @{
"Authorization" = "Basic $auth"
"Content-Type" = "application/json"
}
# Step 1: Create release
Write-Host "`nCreating release v$Version..." -ForegroundColor Yellow
$releaseLookupUrl = "$ForgejoUrl/api/v1/repos/$Repo/releases/tags/v$Version"
$releaseUrl = "$ForgejoUrl/api/v1/repos/$Repo/releases"
# Build release body with checksum info if exe is being uploaded
$releaseBody = "WebDropBridge v$Version`n`n**Release Artifacts:**`n- MSI Installer (Windows Setup)`n"
if (-not $SkipExe) {
$checksum = Get-Content $ChecksumPath -Raw
$releaseBody += "- Portable Executable`n`n**Checksum:**`n$checksum`n"
}
$releaseData = @{
tag_name = "v$Version"
name = "WebDropBridge v$Version"
body = $releaseBody
body = "Shared branded release for WebDrop Bridge v$Version"
draft = $false
prerelease = $false
} | ConvertTo-Json
try {
$response = Invoke-WebRequest -Uri $releaseUrl `
-Method POST `
-Headers $headers `
-Body $releaseData `
-TimeoutSec 30 `
-UseBasicParsing `
-ErrorAction Stop
$lookupResponse = Invoke-WebRequest -Uri $releaseLookupUrl -Method GET -Headers $headers -TimeoutSec 30 -UseBasicParsing -ErrorAction Stop
$releaseInfo = $lookupResponse.Content | ConvertFrom-Json
$releaseId = $releaseInfo.id
Write-Host "[OK] Using existing release (ID: $releaseId)" -ForegroundColor Green
}
catch {
$response = Invoke-WebRequest -Uri $releaseUrl -Method POST -Headers $headers -Body $releaseData -TimeoutSec 30 -UseBasicParsing -ErrorAction Stop
$releaseInfo = $response.Content | ConvertFrom-Json
$releaseId = $releaseInfo.id
Write-Host "[OK] Release created (ID: $releaseId)" -ForegroundColor Green
}
catch {
Write-Host "ERROR creating release: $_" -ForegroundColor Red
exit 1
}
# Setup curl authentication
$curlAuth = "$ForgejoUser`:$ForgejoPW"
$uploadUrl = "$ForgejoUrl/api/v1/repos/$Repo/releases/$releaseId/assets"
# Step 2: Upload MSI installer as primary artifact
Write-Host "`nUploading MSI installer (primary artifact)..." -ForegroundColor Yellow
try {
$response = curl.exe -s -X POST `
-u $curlAuth `
-F "attachment=@$MsiPath" `
$uploadUrl
foreach ($artifact in $artifactPaths) {
$response = curl.exe -s -X POST -u $curlAuth -F "attachment=@$artifact" $uploadUrl
if ($response -like "*error*" -or $response -like "*404*") {
Write-Host "ERROR uploading MSI: $response" -ForegroundColor Red
exit 1
Write-Host "WARNING: Could not upload $artifact : $response" -ForegroundColor Yellow
}
Write-Host "[OK] MSI installer uploaded" -ForegroundColor Green
}
catch {
Write-Host "ERROR uploading MSI: $_" -ForegroundColor Red
exit 1
}
# Step 3: Upload executable as optional artifact (if available)
if (-not $SkipExe) {
Write-Host "`nUploading executable (optional portable version)..." -ForegroundColor Yellow
try {
$response = curl.exe -s -X POST `
-u $curlAuth `
-F "attachment=@$ExePath" `
$uploadUrl
if ($response -like "*error*" -or $response -like "*404*") {
Write-Host "WARNING: Could not upload executable: $response" -ForegroundColor Yellow
}
else {
Write-Host "[OK] Executable uploaded" -ForegroundColor Green
}
}
catch {
Write-Host "WARNING: Could not upload executable: $_" -ForegroundColor Yellow
}
# Step 4: Upload checksum as asset
Write-Host "Uploading checksum..." -ForegroundColor Yellow
try {
$response = curl.exe -s -X POST `
-u $curlAuth `
-F "attachment=@$ChecksumPath" `
$uploadUrl
if ($response -like "*error*" -or $response -like "*404*") {
Write-Host "WARNING: Could not upload checksum: $response" -ForegroundColor Yellow
}
else {
Write-Host "[OK] Checksum uploaded" -ForegroundColor Green
}
}
catch {
Write-Host "WARNING: Could not upload checksum: $_" -ForegroundColor Yellow
else {
Write-Host "[OK] Uploaded $([System.IO.Path]::GetFileName($artifact))" -ForegroundColor Green
}
}