webdrop-bridge/build/scripts/upload_to_packages.ps1
claudi 847692eef6 feat: Add interactive credential prompts to upload scripts
- Scripts now prompt for username/password on first run if not set
- Credentials are saved to session environment variables
- No need to pre-set env vars before running
- Windows: Add -ClearCredentials flag to clear session credentials
- macOS: Add --clear-credentials flag to clear session credentials
- Credentials persist for duration of PowerShell/shell session
- Much simpler UX: just run script and enter credentials when prompted
2026-01-28 14:49:02 +01:00

134 lines
4.2 KiB
PowerShell

# Upload Windows Build to Forgejo Packages
# Usage: .\upload_to_packages.ps1 -Version 1.0.0
# Uses your Forgejo credentials (same as git)
# First run will prompt for credentials and save them to this session
param(
[Parameter(Mandatory=$false)]
[string]$Version,
[Parameter(Mandatory=$false)]
[string]$ForgejoUser,
[Parameter(Mandatory=$false)]
[string]$ForgejoPW,
[switch]$ClearCredentials,
[string]$ForgejoUrl = "https://git.him-tools.de",
[string]$Repo = "HIM-public/webdrop-bridge",
[string]$ExePath = "build\dist\windows\WebDropBridge.exe",
[string]$ChecksumPath = "build\dist\windows\WebDropBridge.exe.sha256"
)
$ErrorActionPreference = "Stop"
# Handle --ClearCredentials flag
if ($ClearCredentials) {
Remove-Item env:FORGEJO_USER -ErrorAction SilentlyContinue
Remove-Item env:FORGEJO_PASS -ErrorAction SilentlyContinue
Write-Host "[OK] Credentials cleared from this session" -ForegroundColor Green
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: .\upload_to_packages.ps1 -ClearCredentials" -ForegroundColor Gray
}
# Verify Version parameter
if (-not $Version) {
Write-Host "ERROR: Version parameter required" -ForegroundColor Red
Write-Host "Usage: .\upload_to_packages.ps1 -Version 1.0.0" -ForegroundColor Yellow
exit 1
}
# Verify files exist
if (-not (Test-Path $ExePath)) {
Write-Host "ERROR: Executable not found at $ExePath" -ForegroundColor Red
exit 1
}
if (-not (Test-Path $ChecksumPath)) {
Write-Host "ERROR: Checksum file not found at $ChecksumPath" -ForegroundColor Red
exit 1
}
Write-Host "Uploading WebDropBridge $Version to Forgejo Packages..." -ForegroundColor Cyan
# Get file info
$exeSize = (Get-Item $ExePath).Length / 1MB
$checksum = Get-Content $ChecksumPath -Raw
Write-Host "File: 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}"))
# Upload executable
Write-Host "`nUploading executable..." -ForegroundColor Yellow
$exeUrl = "$ForgejoUrl/api/v1/repos/$Repo/packages/generic/webdrop-bridge/$Version/WebDropBridge.exe"
$headers = @{
"Authorization" = "Basic $auth"
}
try {
$response = Invoke-WebRequest -Uri $exeUrl `
-Method PUT `
-Headers $headers `
-InFile $ExePath `
-ContentType "application/octet-stream"
Write-Host "[OK] Executable uploaded successfully" -ForegroundColor Green
}
catch {
Write-Host "ERROR uploading executable: $_" -ForegroundColor Red
exit 1
}
# Upload checksum
Write-Host "Uploading checksum..." -ForegroundColor Yellow
$checksumUrl = "$ForgejoUrl/api/v1/repos/$Repo/packages/generic/webdrop-bridge/$Version/WebDropBridge.exe.sha256"
try {
$response = Invoke-WebRequest -Uri $checksumUrl `
-Method PUT `
-Headers $headers `
-Body $checksum `
-ContentType "text/plain"
Write-Host "[OK] Checksum uploaded successfully" -ForegroundColor Green
}
catch {
Write-Host "ERROR uploading checksum: $_" -ForegroundColor Red
exit 1
}
Write-Host "`n[OK] Upload complete!" -ForegroundColor Green
Write-Host "View at: $ForgejoUrl/$Repo/packages" -ForegroundColor Cyan