From 3210ac50d83b2ab7af089b3a8fc03c5a7c039784 Mon Sep 17 00:00:00 2001 From: liuyu65 Date: Sun, 11 Oct 2026 12:17:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E8=84=9A=E6=9C=AC=E5=8A=A0?= =?UTF-8?q?=E5=9B=BA=EF=BC=9ARelease=20=E5=88=9B=E5=BB=BA=E4=B8=8E?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E4=B8=8A=E4=BC=A0=E7=9A=84=20JSON=20?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=AE=B9=E9=94=99=EF=BC=88=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E6=8C=89=20tag=20=E5=A4=8D=E6=A0=B8?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/publish_release.ps1 | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts/publish_release.ps1 b/scripts/publish_release.ps1 index 1204c5a..19d7ec8 100644 --- a/scripts/publish_release.ps1 +++ b/scripts/publish_release.ps1 @@ -84,8 +84,16 @@ if ($rel -and $rel.id) { [System.IO.File]::WriteAllText($tmp, $payload, (New-Object System.Text.UTF8Encoding($false))) Write-Host "创建 Release v$Version ..." $resp = curl.exe -s --max-time 300 -X POST -H "Content-Type: application/json" --data-binary "@$tmp" -u $Auth "$Server/api/v1/repos/$Owner/$Repo/releases" - $rel = $resp | ConvertFrom-Json - if (-not $rel.id) { throw "创建 Release 失败:$resp" } + # 响应解析容错:偶发 JSON 解析异常时按 tag 重新查询(创建可能已成功)。 + $rel = $null + try { $rel = $resp | ConvertFrom-Json } catch { $rel = $null } + if (-not $rel -or -not $rel.id) { + curl.exe -s --max-time 300 -o $tagFile "$Server/api/v1/repos/$Owner/$Repo/releases/tags/v$Version" | Out-Null + try { + $rel = [System.IO.File]::ReadAllText($tagFile, [System.Text.Encoding]::UTF8) | ConvertFrom-Json + } catch { $rel = $null } + } + if (-not $rel -or -not $rel.id) { throw "创建 Release 失败:$resp" } } Write-Host "Release id = $($rel.id)" @@ -106,8 +114,20 @@ function Upload-Asset([string]$path) { } catch {} Write-Host "上传附件:$name (限速 $UploadLimit)..." $r = curl.exe -s --limit-rate $UploadLimit -X POST -F "attachment=@$path" -u $Auth "$Server/api/v1/repos/$Owner/$Repo/releases/$($rel.id)/assets?name=$name" - $asset = $r | ConvertFrom-Json - if (-not $asset.name) { throw "上传失败:$r" } + # 解析容错:异常时按 tag 复核附件是否已存在(上传可能已成功)。 + $asset = $null + try { $asset = $r | ConvertFrom-Json } catch { $asset = $null } + if (-not $asset -or -not $asset.name) { + curl.exe -s --max-time 300 -o $curFile "$Server/api/v1/repos/$Owner/$Repo/releases/tags/v$Version" | Out-Null + $okName = $false + try { + $cur2 = [System.IO.File]::ReadAllText($curFile, [System.Text.Encoding]::UTF8) | ConvertFrom-Json + foreach ($a in $cur2.assets) { + if ($a.name -eq $name) { $okName = $true; $asset = $a } + } + } catch {} + if (-not $okName) { throw "上传失败:$r" } + } Write-Host " 完成:$($asset.browser_download_url)" } Upload-Asset $ApkPath