webdrop-bridge/build/scripts/upload_to_packages.ps1
claudi 1b37335f8a
Some checks are pending
Tests & Quality Checks / Test on Python 3.11 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-1 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.10 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.11-2 (push) Waiting to run
Tests & Quality Checks / Test on Python 3.12-2 (push) Waiting to run
Tests & Quality Checks / Build Artifacts (push) Blocked by required conditions
Tests & Quality Checks / Build Artifacts-1 (push) Blocked by required conditions
refactor: Use environment variables for upload script authentication
- Add FORGEJO_TOKEN environment variable support to both upload scripts
- Windows: Add Credential Manager storage via -SaveToken flag
- macOS: Add config file storage via --save-token flag
- Scripts now check: parameter -> env var -> credential manager/config
- Update FORGEJO_PACKAGES_SETUP.md with all authentication methods
- Token is now optional - scripts find it automatically
- Matches git authentication workflow
2026-01-28 14:29:35 +01:00

144 lines
4.4 KiB
PowerShell

# Upload Windows Build to Forgejo Packages
# Usage: .\upload_to_packages.ps1 -Version 1.0.0
# Set token via: $env:FORGEJO_TOKEN = "your_token"
# Or store in Credential Manager: .\upload_to_packages.ps1 -SaveToken
param(
[Parameter(Mandatory=$false)]
[string]$Version,
[Parameter(Mandatory=$false)]
[string]$ForgejoToken,
[switch]$SaveToken,
[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"
)
# Helper function to manage credentials
function Get-ForgejoToken {
param([switch]$Save, [string]$Token)
if ($Save -and $Token) {
# Save to Credential Manager
$cred = New-Object System.Management.Automation.PSCredential(
"forgejo",
(ConvertTo-SecureString $Token -AsPlainText -Force)
)
$cred | Export-Clixml -Path "$env:APPDATA\forgejo_token.xml" -Force
Write-Host "✓ Token saved to Credential Manager" -ForegroundColor Green
return $Token
}
# Try to load from Credential Manager
if (Test-Path "$env:APPDATA\forgejo_token.xml") {
$cred = Import-Clixml -Path "$env:APPDATA\forgejo_token.xml"
return $cred.GetNetworkCredential().Password
}
return $null
}
# Handle -SaveToken flag
if ($SaveToken) {
if (-not $ForgejoToken) {
$ForgejoToken = Read-Host "Enter Forgejo token to save" -AsSecureString | %{[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($_))}
}
Get-ForgejoToken -Save -Token $ForgejoToken
exit 0
}
$ErrorActionPreference = "Stop"
# Get token from sources (in order of priority)
if (-not $ForgejoToken) {
# Try environment variable first
$ForgejoToken = $env:FORGEJO_TOKEN
}
if (-not $ForgejoToken) {
# Try Credential Manager
$ForgejoToken = Get-ForgejoToken
}
if (-not $ForgejoToken) {
Write-Host "ERROR: No Forgejo token found!" -ForegroundColor Red
Write-Host "Set token using one of these methods:" -ForegroundColor Yellow
Write-Host " 1. Environment variable: `$env:FORGEJO_TOKEN = 'your_token'"
Write-Host " 2. Credential Manager: .\upload_to_packages.ps1 -SaveToken"
Write-Host " 3. Parameter: -ForgejoToken 'your_token'"
exit 1
}
# 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))..."
# Upload executable
Write-Host "`nUploading executable..." -ForegroundColor Yellow
$exeUrl = "$ForgejoUrl/api/v1/repos/$Repo/packages/generic/webdrop-bridge/$Version/WebDropBridge.exe"
$headers = @{
"Authorization" = "token $ForgejoToken"
}
try {
$response = Invoke-WebRequest -Uri $exeUrl `
-Method PUT `
-Headers $headers `
-InFile $ExePath `
-ContentType "application/octet-stream"
Write-Host "✓ 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 "✓ Checksum uploaded successfully" -ForegroundColor Green
}
catch {
Write-Host "ERROR uploading checksum: $_" -ForegroundColor Red
exit 1
}
Write-Host "`n✓ Upload complete!" -ForegroundColor Green
Write-Host "View at: $ForgejoUrl/$Repo/packages" -ForegroundColor Cyan