From 18f6bccaa34325760232b59aab0857168c03ab12 Mon Sep 17 00:00:00 2001 From: denglihong2007 <2639367181@qq.com> Date: Sun, 2 Mar 2025 12:48:10 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E5=86=8D=E6=AC=A1=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 57 ++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4a54d98..bb9f5fc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -94,20 +94,27 @@ jobs: # 获取最新 Release 版本号 $latestTag = gh release list --limit 1 --json tagName --jq ".[0].tagName" 2>$null if (-not $latestTag) { - $latestTag = "" + $latestTag = "" } + $originalOutputEncoding = [Console]::OutputEncoding + [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 - # 初始化日志文件 - $releaseNotesPath = "release_notes.md" - Set-Content -Path $releaseNotesPath -Value "## 更新日志" + try { + # 初始化日志文件(UTF-8 编码) + $releaseNotesPath = "release_notes.md" - # 如果没有最新 Release,则获取所有 commit - if (-not $latestTag) { - Add-Content -Path $releaseNotesPath -Value "`n### 初始版本" - $commitLogs = git log --pretty=format:"%s" - } else { - Add-Content -Path $releaseNotesPath -Value "`n### 更新日志 (从 $latestTag)" - $commitLogs = git log $latestTag..HEAD --pretty=format:"%s" + # 获取 Commit 日志 + if (-not $latestTag) { + Set-Content -Path $releaseNotesPath -Value "## 初始版本" -Encoding UTF8 + $commitLogs = git log --pretty=format:"%s" + } else { + $latestTag += "..HEAD" + Set-Content -Path $releaseNotesPath -Value "## 更新日志" -Encoding UTF8 + $commitLogs = git log $latestTag --pretty=format:"%s" + } + } finally { + # 恢复原始编码设置 + [Console]::OutputEncoding = $originalOutputEncoding } # 解析 Conventional Commits @@ -116,29 +123,29 @@ jobs: $others = @() foreach ($log in $commitLogs) { - if ($log -match "^feat!:? (.+)") { - $features += "- 🚀 **$($matches[1])**" - } elseif ($log -match "^fix!:? (.+)") { - $fixes += "- 🐛 **$($matches[1])**" - } elseif ($log -match "^(chore|docs|refactor|test|style): (.+)") { - $others += "- 🔧 **$($matches[2])**" - } + if ($log -match "^feat!:? (.+)") { + $features += "- 🚀 **$($matches[1])**" + } elseif ($log -match "^fix!:? (.+)") { + $fixes += "- 🐛 **$($matches[1])**" + } elseif ($log -match "^(chore|docs|refactor|test|style): (.+)") { + $others += "- 🔧 **$($matches[2])**" + } } - # 写入日志文件 + # 写入日志文件(UTF-8 编码) if ($features.Count -gt 0) { - Add-Content -Path $releaseNotesPath -Value "`n### ✨ 特性 (Features)`n" - Add-Content -Path $releaseNotesPath -Value ($features -join "`n") + Add-Content -Path $releaseNotesPath -Value "`n### ✨ 特性`n" -Encoding UTF8 + Add-Content -Path $releaseNotesPath -Value ($features -join "`n") -Encoding UTF8 } if ($fixes.Count -gt 0) { - Add-Content -Path $releaseNotesPath -Value "`n### 🐞 修复 (Fixes)`n" - Add-Content -Path $releaseNotesPath -Value ($fixes -join "`n") + Add-Content -Path $releaseNotesPath -Value "`n### 🐞 修复`n" -Encoding UTF8 + Add-Content -Path $releaseNotesPath -Value ($fixes -join "`n") -Encoding UTF8 } if ($others.Count -gt 0) { - Add-Content -Path $releaseNotesPath -Value "`n### 🛠 其他更新 (Other Updates)`n" - Add-Content -Path $releaseNotesPath -Value ($others -join "`n") + Add-Content -Path $releaseNotesPath -Value "`n### 🛠 其他更新`n" -Encoding UTF8 + Add-Content -Path $releaseNotesPath -Value ($others -join "`n") -Encoding UTF8 } - name: Create GitHub Release