-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathupload_github_release_win.ps1
More file actions
69 lines (59 loc) · 2.64 KB
/
Copy pathupload_github_release_win.ps1
File metadata and controls
69 lines (59 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 上传 Windows 构建产物(NSIS .exe)到 GitHub Release
# 可独立运行,也被 publish_windows.ps1 调用
#
# 用法: .\upload_github_release_win.ps1
$ErrorActionPreference = "Stop"
$ProjectDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $ProjectDir
# 读取版本号
$TauriConf = Get-Content "src-tauri\tauri.conf.json" -Raw | ConvertFrom-Json
$Version = $TauriConf.version
Write-Host ""
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host " 上传 Windows 产物到 GitHub Release" -ForegroundColor Cyan
Write-Host " Version: v$Version" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host ""
# 检查 gh CLI
$ghCmd = Get-Command gh -ErrorAction SilentlyContinue
if (-not $ghCmd) {
Write-Host "[X] gh CLI 未安装" -ForegroundColor Red
Write-Host " 安装: winget install --id GitHub.cli" -ForegroundColor Yellow
throw "gh CLI 未安装"
}
# 查找 NSIS .exe 文件
$TargetDir = Join-Path $ProjectDir "src-tauri\target\x86_64-pc-windows-msvc\release\bundle\nsis"
$NsisExe = Get-ChildItem -Path $TargetDir -Filter "*.exe" -ErrorAction SilentlyContinue | Where-Object { $_.Name -notmatch "portable" } | Select-Object -First 1
if (-not $NsisExe) {
Write-Host "[X] 未找到 NSIS 安装包" -ForegroundColor Red
Write-Host " 请先运行 .\build_windows.ps1 完成构建" -ForegroundColor Yellow
throw "未找到 NSIS 安装包"
}
Write-Host " [OK] $($NsisExe.Name)" -ForegroundColor Green
Write-Host ""
# 检查 Release 是否存在 (临时放宽 ErrorAction,gh stderr 输出不应触发终止)
$prevEAP = $ErrorActionPreference
$ErrorActionPreference = "Continue"
$releaseCheck = & gh release view "v$Version" 2>&1
$ghExitCode = $LASTEXITCODE
$ErrorActionPreference = $prevEAP
if ($ghExitCode -ne 0) {
Write-Host "[X] GitHub Release v$Version 不存在" -ForegroundColor Red
Write-Host " 请先通过 merge-release 流程创建 Release" -ForegroundColor Yellow
throw "GitHub Release v$Version 不存在"
}
# 上传 (临时放宽 ErrorAction,gh 进度输出走 stderr)
Write-Host "上传到 GitHub Release v$Version..." -ForegroundColor Cyan
$prevEAP = $ErrorActionPreference
$ErrorActionPreference = "Continue"
& gh release upload "v$Version" $NsisExe.FullName --clobber
$ghExitCode = $LASTEXITCODE
$ErrorActionPreference = $prevEAP
if ($ghExitCode -eq 0) {
Write-Host ""
Write-Host "[OK] GitHub Release 上传完成" -ForegroundColor Green
Write-Host " - $($NsisExe.Name)" -ForegroundColor White
} else {
Write-Host "[X] 上传失败" -ForegroundColor Red
throw "GitHub Release 上传失败"
}