Release Healer Man 0.1.4

This commit is contained in:
phenom
2026-08-18 12:06:04 -04:00
parent 5bb170039a
commit f4c9cf356c
63 changed files with 2694 additions and 81 deletions
+63 -15
View File
@@ -8,7 +8,8 @@ param(
[int]$VersionCode,
[string]$ReleaseNotes = 'Healer Man Android update.',
[string]$GiteaBaseUrl = 'https://git.whoagland.com',
[string]$GiteaBaseUrl = 'http://192.168.1.180:30008',
[string]$GiteaPublicBaseUrl = 'https://git.whoagland.com',
[string]$Owner = 'phenom',
[string]$Repository = 'healer-man'
)
@@ -67,7 +68,7 @@ try {
[IO.File]::WriteAllText($checksumPath, "$checksum $apkName`n", [Text.UTF8Encoding]::new($false))
$apiRoot = $GiteaBaseUrl.TrimEnd('/') + '/api/v1'
$headers = @{ Authorization = "token $env:GITEA_TOKEN" }
$headers = @{ Authorization = "token $($env:GITEA_TOKEN.Trim())" }
$tag = "v$VersionName"
$releaseBody = @{
tag_name = $tag
@@ -77,26 +78,73 @@ try {
draft = $false
prerelease = $false
} | ConvertTo-Json
$release = Invoke-RestMethod `
-Method Post `
-Uri "$apiRoot/repos/$Owner/$Repository/releases" `
-Headers $headers `
-ContentType 'application/json' `
-Body $releaseBody
$encodedTag = [Uri]::EscapeDataString($tag)
try {
$release = Invoke-RestMethod `
-Method Get `
-Uri "$apiRoot/repos/$Owner/$Repository/releases/tags/$encodedTag" `
-Headers $headers
Write-Host "Resuming existing Gitea release $tag."
} catch {
$statusCode = if ($_.Exception.Response) { [int]$_.Exception.Response.StatusCode } else { 0 }
if ($statusCode -ne 404) { throw }
$release = Invoke-RestMethod `
-Method Post `
-Uri "$apiRoot/repos/$Owner/$Repository/releases" `
-Headers $headers `
-ContentType 'application/json' `
-Body $releaseBody
}
foreach ($attachment in @($apkPath, $checksumPath)) {
$attachmentName = Split-Path -Leaf $attachment
$attachmentSize = (Get-Item -LiteralPath $attachment).Length
$encodedName = [Uri]::EscapeDataString($attachmentName)
Invoke-RestMethod `
-Method Post `
-Uri "$apiRoot/repos/$Owner/$Repository/releases/$($release.id)/assets?name=$encodedName" `
-Headers $headers `
-ContentType 'application/octet-stream' `
-InFile $attachment | Out-Null
$release = Invoke-RestMethod `
-Method Get `
-Uri "$apiRoot/repos/$Owner/$Repository/releases/$($release.id)" `
-Headers $headers
$existingAsset = @($release.assets | Where-Object { $_.name -eq $attachmentName }) |
Select-Object -First 1
if ($existingAsset) {
if ([long]$existingAsset.size -ne $attachmentSize) {
throw "Release asset $attachmentName exists with the wrong size ($($existingAsset.size), expected $attachmentSize)."
}
Write-Host "Release asset $attachmentName already exists with the expected size; skipping upload."
continue
}
$uploaded = $false
for ($attempt = 1; $attempt -le 3 -and -not $uploaded; $attempt++) {
try {
Invoke-RestMethod `
-Method Post `
-Uri "$apiRoot/repos/$Owner/$Repository/releases/$($release.id)/assets?name=$encodedName" `
-Headers $headers `
-ContentType 'application/octet-stream' `
-InFile $attachment | Out-Null
$uploaded = $true
} catch {
$refreshedRelease = Invoke-RestMethod `
-Method Get `
-Uri "$apiRoot/repos/$Owner/$Repository/releases/$($release.id)" `
-Headers $headers
$uploadedAsset = @($refreshedRelease.assets | Where-Object {
$_.name -eq $attachmentName -and [long]$_.size -eq $attachmentSize
}) | Select-Object -First 1
if ($uploadedAsset) {
$uploaded = $true
continue
}
if ($attempt -eq 3) { throw }
Write-Warning "Upload attempt $attempt for $attachmentName failed; retrying through the LAN API."
Start-Sleep -Seconds ([math]::Pow(2, $attempt))
}
}
}
Write-Host "Published $tag with $apkName and its SHA-256 checksum."
Write-Host "$GiteaBaseUrl/$Owner/$Repository/releases/tag/$tag"
Write-Host "$($GiteaPublicBaseUrl.TrimEnd('/'))/$Owner/$Repository/releases/tag/$tag"
} finally {
Pop-Location
}