92 lines
3.5 KiB
PowerShell
92 lines
3.5 KiB
PowerShell
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$Version,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[string]$ForgejoToken =$env:FORGEJO_TOKEN,
|
|
|
|
[string]$Server = "https://git.kellsupport.com",
|
|
[string]$Owner = "mtkell",
|
|
[string]$Repo = "glp-companion"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
if (-not $ForgejoToken) {
|
|
Write-Error "Forgejo Token missing! Pass -ForgejoToken <token> or set `$env:FORGEJO_TOKEN."
|
|
}
|
|
|
|
$DistDir = "dist\v$Version"
|
|
$Tag = "v$Version"
|
|
|
|
Write-Host "==================================================" -ForegroundColor Cyan
|
|
Write-Host " Building & Publishing Alpha Release: $Tag" -ForegroundColor Cyan
|
|
Write-Host " Target: $Server/$Owner/$Repo" -ForegroundColor Cyan
|
|
Write-Host "==================================================" -ForegroundColor Cyan
|
|
|
|
New-Item -ItemType Directory -Force -Path $DistDir | Out-Null
|
|
|
|
Write-Host "`n[1/5] Running Drift build_runner..." -ForegroundColor Yellow
|
|
dart run build_runner build --delete-conflicting-outputs
|
|
|
|
Write-Host "`n[2/5] Building Android arm64 APK..." -ForegroundColor Yellow
|
|
flutter build apk --release --split-per-abi
|
|
$ApkSrc = "build\app\outputs\flutter-apk\app-arm64-v8a-release.apk"
|
|
$ApkDest = "$DistDir\GLP1Companion-Android-arm64-$Tag.apk"
|
|
Copy-Item $ApkSrc $ApkDest -Force
|
|
|
|
Write-Host "`n[3/5] Building Windows Release & Packaging Standalone Zip..." -ForegroundColor Yellow
|
|
flutter build windows --release
|
|
$ZipDest = "$DistDir\GLP1Companion-Windows-x64-$Tag-Portable.zip"
|
|
Compress-Archive -Path "build\windows\x64\runner\Release\*" -DestinationPath $ZipDest -Force
|
|
|
|
Write-Host "`n[4/5] Building Windows MSIX..." -ForegroundColor Yellow
|
|
dart run msix:create --install-certificate false
|
|
$MsixSrc = Get-ChildItem "build\windows\x64\runner\Release\*.msix" | Select-Object -First 1
|
|
$MsixDest = "$DistDir\GLP1Companion-Windows-$Tag.msix"
|
|
Copy-Item $MsixSrc.FullName $MsixDest -Force
|
|
|
|
Write-Host "`n[5/5] Publishing Release & Assets to Forgejo..." -ForegroundColor Yellow
|
|
$Headers = @{
|
|
"Authorization" = "token $ForgejoToken"
|
|
"Accept" = "application/json"
|
|
}
|
|
|
|
$ReleaseBody = @{
|
|
tag_name = $Tag
|
|
name = "GLP-1 Companion $Tag"
|
|
body = "Automated alpha release build for $Tag containing Android APK and Windows packages."
|
|
draft = $false
|
|
prerelease = $true
|
|
} | ConvertTo-Json
|
|
|
|
$ReleaseUrl = "$Server/api/v1/repos/$Owner/$Repo/releases"
|
|
|
|
try {
|
|
$ReleaseResp = Invoke-RestMethod -Uri $ReleaseUrl -Method Post -Headers $Headers -Body $ReleaseBody -ContentType "application/json"
|
|
$ReleaseId = $ReleaseResp.id
|
|
Write-Host "Created release $ReleaseId for$Tag" -ForegroundColor Green
|
|
} catch {
|
|
Write-Host "Release for $Tag may already exist, fetching existing ID..." -ForegroundColor Gray
|
|
$Existing = Invoke-RestMethod -Uri "$ReleaseUrl/tags/$Tag" -Method Get -Headers $Headers
|
|
$ReleaseId = $Existing.id
|
|
Write-Host "Using existing release ID: $ReleaseId" -ForegroundColor Green
|
|
}
|
|
|
|
$Assets = @($ApkDest, $ZipDest,$MsixDest)
|
|
|
|
foreach ($FilePath in $Assets) {
|
|
if (Test-Path $FilePath) {
|
|
$FileName = [System.IO.Path]::GetFileName($FilePath)
|
|
Write-Host "Uploading $FileName..." -ForegroundColor Cyan
|
|
|
|
& curl.exe -s -X POST "$Server/api/v1/repos/$Owner/$Repo/releases/$ReleaseId/assets?name=$FileName" `
|
|
-H "Authorization: token $ForgejoToken" `
|
|
-H "Content-Type: multipart/form-data" `
|
|
-F "attachment=@$FilePath" | Out-Null
|
|
|
|
Write-Host " -> Uploaded $FileName" -ForegroundColor Green
|
|
}
|
|
}
|
|
|
|
Write-Host "`nSuccessfully released $Tag to$Server/$Owner/$Repo/releases!" -ForegroundColor Green |