From c479da1c9f6bb6e9e5e223ccbc6c85fe8e520d30 Mon Sep 17 00:00:00 2001 From: denglihong2007 <2639367181@qq.com> Date: Sun, 2 Mar 2025 15:06:31 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=9A=82=E6=97=B6=E6=94=BE=E5=BC=83?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 157 ---------------------------------- 1 file changed, 157 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index bb9f5fc..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,157 +0,0 @@ -name: Release on Version Change - -on: - push: - branches: - - master - -permissions: - contents: write - pull-requests: read - -jobs: - check-version: - runs-on: windows-latest - outputs: - version_updated: ${{ steps.check_version.outputs.updated }} - new_version: ${{ steps.get_version.outputs.version }} - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 # 获取全部提交历史以便比较标签 - - - name: Setup .NET 9.0 - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '9.0.x' - - - name: Extract version from csproj - id: get_version - shell: pwsh - run: | - [xml]$csproj = Get-Content "./CRSim/CRSim.csproj" - # 确保选择包含Version的PropertyGroup - $version = $csproj.Project.PropertyGroup.Version - echo "Detected version: $version" - # 将版本设置为步骤输出 - echo "version=$version" >> $env:GITHUB_OUTPUT - - - name: Compare with latest tag - id: check_version - shell: pwsh - run: | - # 获取最新标签(按语义版本排序) - $latestTag = git tag --list --sort=-v:refname | Select-Object -First 1 - echo "Latest tag: $latestTag" - - # 获取csproj中的版本 - $currentVersion = "${{ steps.get_version.outputs.version }}" - - if (-not $latestTag) { - echo "首次发布,没有现有标签" - echo "updated=true" >> $env:GITHUB_OUTPUT - } elseif ($currentVersion -ne $latestTag) { - echo "检测到新版本: $currentVersion (旧版本: $latestTag)" - echo "updated=true" >> $env:GITHUB_OUTPUT - } else { - echo "版本未变化,跳过发布" - echo "updated=false" >> $env:GITHUB_OUTPUT - } - - release: - needs: check-version - if: ${{ needs.check-version.outputs.version_updated == 'true' }} - runs-on: windows-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Setup .NET 9.0 - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '9.0.x' - - - name: Restore and Build - run: | - dotnet restore - dotnet build --configuration Release --no-restore - - - name: Publish - run: dotnet publish -c Release -o out - - - name: Create Zip Package - shell: pwsh - run: | - $version = "${{ needs.check-version.outputs.new_version }}" - Compress-Archive -Path out/* -DestinationPath "CRSim-release-$version.zip" - - - name: Generate Release Notes - id: release_notes - shell: pwsh - run: | - # 获取最新 Release 版本号 - $latestTag = gh release list --limit 1 --json tagName --jq ".[0].tagName" 2>$null - if (-not $latestTag) { - $latestTag = "" - } - $originalOutputEncoding = [Console]::OutputEncoding - [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 - - try { - # 初始化日志文件(UTF-8 编码) - $releaseNotesPath = "release_notes.md" - - # 获取 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 - $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])**" - } - } - - # 写入日志文件(UTF-8 编码) - if ($features.Count -gt 0) { - 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### 🐞 修复`n" -Encoding UTF8 - Add-Content -Path $releaseNotesPath -Value ($fixes -join "`n") -Encoding UTF8 - } - - if ($others.Count -gt 0) { - Add-Content -Path $releaseNotesPath -Value "`n### 🛠 其他更新`n" -Encoding UTF8 - Add-Content -Path $releaseNotesPath -Value ($others -join "`n") -Encoding UTF8 - } - - - name: Create GitHub Release - uses: softprops/action-gh-release@v2 - with: - tag_name: v${{ needs.check-version.outputs.new_version }} - name: ${{ needs.check-version.outputs.new_version }} - body_path: release_notes.md - files: CRSim-release-${{ needs.check-version.outputs.new_version }}.zip \ No newline at end of file