Publish NuGet to releases #825
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish NuGet to releases | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: '发布版本号 (例如: 1.0.0)' | |
| required: true | |
| type: string | |
| jobs: | |
| build-and-publish: | |
| runs-on: windows-latest | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v6 | |
| - name: 安装.NET SDK | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: '10.0.x' # 支持GeneralUpdate.Drivelution的.NET 10目标框架 | |
| - name: 恢复依赖 | |
| run: dotnet restore ./src/c#/GeneralUpdate.slnx # 使用解决方案统一恢复 | |
| - name: 构建项目(确保生成DLL) | |
| run: dotnet build ./src/c#/GeneralUpdate.slnx -c Release --no-restore # 显式构建,避免重复恢复 | |
| - name: 打包NuGet包 | |
| run: | | |
| $projects = @( | |
| "GeneralUpdate.Bowl", | |
| "GeneralUpdate.ClientCore", | |
| "GeneralUpdate.Common", | |
| "GeneralUpdate.Core", | |
| "GeneralUpdate.Differential", | |
| "GeneralUpdate.Drivelution", | |
| "GeneralUpdate.Extension" | |
| ) | |
| foreach ($project in $projects) { | |
| dotnet pack ./src/c#/$project/$project.csproj ` | |
| -c Release ` | |
| -o ./nupkgs ` | |
| -p:Version=${{ github.event.inputs.version }} ` | |
| -p:PackageVersion=${{ github.event.inputs.version }} ` | |
| --no-build # 避免重复构建,使用已生成的文件 | |
| } | |
| shell: pwsh | |
| - name: 生成更新日志 | |
| shell: pwsh | |
| run: | | |
| $previousTag = git describe --tags --abbrev=0 --always 2>$null | |
| if ($LASTEXITCODE -ne 0 -or -not $previousTag) { | |
| $log = git log --oneline --no-decorate -100 | |
| } else { | |
| $log = git log "${previousTag}..HEAD" --oneline --no-decorate | |
| } | |
| $features = @() | |
| $fixes = @() | |
| $refactors = @() | |
| $tests = @() | |
| $docs = @() | |
| $chores = @() | |
| $others = @() | |
| foreach ($line in ($log -split "`n")) { | |
| $line = $line.Trim() | |
| if (-not $line) { continue } | |
| # Remove leading commit hash | |
| $msg = $line -replace '^[a-f0-9]+\s+', '' | |
| if ($msg -match '^(feat|feature)') { $features += "- $msg" } | |
| elseif ($msg -match '^fix') { $fixes += "- $msg" } | |
| elseif ($msg -match '^refactor') { $refactors += "- $msg" } | |
| elseif ($msg -match '^test') { $tests += "- $msg" } | |
| elseif ($msg -match '^docs') { $docs += "- $msg" } | |
| elseif ($msg -match '^(chore|cleanup|ci|build)') { $chores += "- $msg" } | |
| else { $others += "- $msg" } | |
| } | |
| $body = "" | |
| function append-section($title, $items) { | |
| if ($items.Count -gt 0) { | |
| $script:body += "## $title`n`n$($items -join "`n")`n`n" | |
| } | |
| } | |
| append-section "🚀 Features" $features | |
| append-section "🐛 Bug Fixes" $fixes | |
| append-section "♻️ Refactoring" $refactors | |
| append-section "✅ Tests" $tests | |
| append-section "📝 Documentation" $docs | |
| append-section "🔧 Chores" $chores | |
| append-section "📦 Other Changes" $others | |
| if (-not $body) { | |
| $body = "_No changes detected between tags._" | |
| } | |
| $body | Out-File -FilePath changelog.md -Encoding UTF8 | |
| Write-Host "=== 生成的更新日志 ===" | |
| Write-Host $body | |
| - name: 创建GitHub Release并上传NuGet包 | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| tag_name: v${{ github.event.inputs.version }} | |
| name: Release v${{ github.event.inputs.version }} | |
| body_path: changelog.md | |
| files: ./nupkgs/*.nupkg | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |