From 609f1e9d6218987a59da89d4814851afd04b7ebc Mon Sep 17 00:00:00 2001 From: denglihong2007 <2639367181@qq.com> Date: Sun, 2 Mar 2025 11:54:22 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=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 | 65 ++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cac495b..4a54d98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -85,25 +85,66 @@ jobs: shell: pwsh run: | $version = "${{ needs.check-version.outputs.new_version }}" - Compress-Archive -Path out/* -DestinationPath "release-$version.zip" + Compress-Archive -Path out/* -DestinationPath "CRSim-release-$version.zip" - name: Generate Release Notes id: release_notes shell: pwsh run: | - $latestTag = git describe --tags --abbrev=0 2>$null || echo "" - if (-not $latestTag) { - echo "## 初始版本" > release_notes.md - git log --pretty=format:"- %s" >> release_notes.md - } else { - echo "## 更新日志 (从 $latestTag)" > release_notes.md - git log $latestTag..HEAD --pretty=format:"- %s" --merges --grep="Merge pull request" >> release_notes.md - } + # 获取最新 Release 版本号 + $latestTag = gh release list --limit 1 --json tagName --jq ".[0].tagName" 2>$null + if (-not $latestTag) { + $latestTag = "" + } + + # 初始化日志文件 + $releaseNotesPath = "release_notes.md" + Set-Content -Path $releaseNotesPath -Value "## 更新日志" + + # 如果没有最新 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" + } + + # 解析 Conventional Commits + $features = @() + $fixes = @() + $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 ($features.Count -gt 0) { + Add-Content -Path $releaseNotesPath -Value "`n### ✨ 特性 (Features)`n" + Add-Content -Path $releaseNotesPath -Value ($features -join "`n") + } + + if ($fixes.Count -gt 0) { + Add-Content -Path $releaseNotesPath -Value "`n### 🐞 修复 (Fixes)`n" + Add-Content -Path $releaseNotesPath -Value ($fixes -join "`n") + } + + if ($others.Count -gt 0) { + Add-Content -Path $releaseNotesPath -Value "`n### 🛠 其他更新 (Other Updates)`n" + Add-Content -Path $releaseNotesPath -Value ($others -join "`n") + } - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: - tag_name: ${{ needs.check-version.outputs.new_version }} - name: Release ${{ needs.check-version.outputs.new_version }} + tag_name: v${{ needs.check-version.outputs.new_version }} + name: ${{ needs.check-version.outputs.new_version }} body_path: release_notes.md - files: release-${{ needs.check-version.outputs.new_version }}.zip \ No newline at end of file + files: CRSim-release-${{ needs.check-version.outputs.new_version }}.zip \ No newline at end of file