|
| 1 | +. "$PSScriptRoot\common.ps1" |
| 2 | + |
| 3 | +Write-Host "`n=== Kira 发布脚本 ===" -ForegroundColor Green |
| 4 | + |
| 5 | +try { |
| 6 | + # 1. 获取当前最新的tag |
| 7 | + $currentTag = Get-CurrentTag |
| 8 | + Write-Host "当前最新tag: $currentTag" -ForegroundColor Yellow |
| 9 | + |
| 10 | + # 解析版本号 |
| 11 | + $version = $currentTag.Substring(1) |
| 12 | + $parts = $version.Split('.') | ForEach-Object { [int]$_ } |
| 13 | + $major, $minor, $patch = $parts |
| 14 | + |
| 15 | + $nextPatch = "v$major.$minor.$($patch + 1)" |
| 16 | + $nextMinor = "v$major.$($minor + 1).0" |
| 17 | + $nextMajor = "v$($major + 1).0.0" |
| 18 | + |
| 19 | + Write-Host "`n请选择新版本号:" |
| 20 | + Write-Host " 1) Patch: $nextPatch" |
| 21 | + Write-Host " 2) Minor: $nextMinor" |
| 22 | + Write-Host " 3) Major: $nextMajor" |
| 23 | + Write-Host " 4) 手动输入" |
| 24 | + $choice = Read-Host "请输入选项 (1-4)" |
| 25 | + |
| 26 | + switch ($choice) { |
| 27 | + '1' { $newTag = $nextPatch } |
| 28 | + '' { $newTag = $nextPatch } |
| 29 | + '2' { $newTag = $nextMinor } |
| 30 | + '3' { $newTag = $nextMajor } |
| 31 | + '4' { |
| 32 | + $newTag = Read-Host "请输入新版本号 (格式: v1.2.3)" |
| 33 | + if ($newTag -notmatch '^v\d+\.\d+\.\d+$') { |
| 34 | + Write-Host "错误: 版本号格式不正确" -ForegroundColor Red |
| 35 | + exit 1 |
| 36 | + } |
| 37 | + } |
| 38 | + default { |
| 39 | + Write-Host "无效选项" -ForegroundColor Red |
| 40 | + exit 1 |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + Write-Host "`n新版本: $newTag" -ForegroundColor Green |
| 45 | + |
| 46 | + # 2. 使用 gen-commit 生成 CHANGELOG.md |
| 47 | + Write-Host "`n正在更新 CHANGELOG.md..." -ForegroundColor Yellow |
| 48 | + Invoke-RunCommand gen-commit @() |
| 49 | + Write-Host "CHANGELOG.md 已更新" -ForegroundColor Green |
| 50 | + |
| 51 | + # 打开编辑器 |
| 52 | + Write-Host "`n正在打开 CHANGELOG.md 供编辑..." -ForegroundColor Yellow |
| 53 | + try { Start-Process zed -ArgumentList 'docs/CHANGELOG.md' -ErrorAction Stop } |
| 54 | + catch { |
| 55 | + try { Start-Process code -ArgumentList 'docs/CHANGELOG.md' -ErrorAction Stop } |
| 56 | + catch { |
| 57 | + Write-Host "无法打开编辑器: $_" -ForegroundColor Red |
| 58 | + Write-Host "请手动编辑 docs/CHANGELOG.md" |
| 59 | + } |
| 60 | + } |
| 61 | + Read-Host "`n编辑完成后按回车继续" |
| 62 | + |
| 63 | + # 3. 更新pubspec.yaml中的版本号 |
| 64 | + Write-Host "`n正在更新 pubspec.yaml..." -ForegroundColor Yellow |
| 65 | + $newVersion = $newTag.Substring(1) |
| 66 | + Update-PubspecVersion $newVersion |
| 67 | + Write-Host "pubspec.yaml 版本号已更新为 $newVersion" -ForegroundColor Green |
| 68 | + |
| 69 | + # 4. Git操作 |
| 70 | + Write-Host "`n正在提交更改..." -ForegroundColor Yellow |
| 71 | + Invoke-RunCommand git @('add', 'docs/CHANGELOG.md', 'pubspec.yaml') |
| 72 | + Invoke-RunCommand git @('commit', '-m', "chore: release $newTag") |
| 73 | + Write-Host "已创建commit" -ForegroundColor Green |
| 74 | + |
| 75 | + # 5. 创建tag |
| 76 | + Write-Host "`n正在创建tag..." -ForegroundColor Yellow |
| 77 | + Invoke-RunCommand git @('tag', '-a', $newTag, '-m', "Release $newTag") |
| 78 | + Write-Host "已创建tag: $newTag" -ForegroundColor Green |
| 79 | + |
| 80 | + # 推送 |
| 81 | + Write-Host "`n正在推送到远程仓库..." -ForegroundColor Yellow |
| 82 | + Invoke-RunCommand git @('push', 'origin', 'main') |
| 83 | + Invoke-RunCommand git @('push', 'origin', $newTag) |
| 84 | + Write-Host "已推送到远程仓库" -ForegroundColor Green |
| 85 | + |
| 86 | + # 6. 输出GitHub Actions链接 |
| 87 | + $repoUrl = Get-RepoUrl |
| 88 | + $repoPath = Get-RepoPath $repoUrl |
| 89 | + |
| 90 | + Write-Host "`n=== 发布完成 ===" -ForegroundColor Green |
| 91 | + Write-Host "版本: $newTag" -ForegroundColor Green |
| 92 | + if ($repoPath) { |
| 93 | + Write-Host "GitHub Actions: https://github.com/$repoPath/actions" -ForegroundColor Yellow |
| 94 | + } |
| 95 | +} |
| 96 | +catch { |
| 97 | + Write-Host "错误: $_" -ForegroundColor Red |
| 98 | + exit 1 |
| 99 | +} |
0 commit comments