-
Notifications
You must be signed in to change notification settings - Fork 74
161 lines (142 loc) · 5.91 KB
/
Copy pathdotnet-ci.yaml
File metadata and controls
161 lines (142 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Publish NuGet to releases
on:
workflow_dispatch:
inputs:
version:
description: '发布版本号 (例如: 10.5.0-beta.7 或 v10.5.0-beta.7,v 前缀可选)'
required: true
type: string
jobs:
build-and-publish:
runs-on: windows-latest
permissions:
contents: write # 创建 Release
id-token: write # 用于 nuget.org Trusted Publishing (OIDC)
steps:
- name: 检出代码
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all tags so changelog generation works
- name: 安装.NET SDK
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x' # 支持GeneralUpdate.Drivelution的.NET 10目标框架
- name: 标准化版本号
id: normalize
shell: pwsh
run: |
$raw = '${{ github.event.inputs.version }}'.Trim()
if ($raw.StartsWith('v') -or $raw.StartsWith('V')) {
$raw = $raw.Substring(1)
}
# Validate is a valid SemVer-like string (digits.digits.digits[-prerelease])
if ($raw -notmatch '^\d+\.\d+\.\d+(-[\w.-]+)?(\+[\w.-]+)?$') {
Write-Error "Invalid version string: '${{ github.event.inputs.version }}' (after stripping prefix: '$raw'). Expected format: 1.0.0 or 1.0.0-beta.1"
exit 1
}
Write-Host "Normalized version: $raw"
echo "version=$raw" >> $env:GITHUB_OUTPUT
- name: 恢复依赖
run: dotnet restore ./src/GeneralUpdate.slnx # 使用解决方案统一恢复
- name: 构建项目(确保生成DLL)
run: dotnet build ./src/GeneralUpdate.slnx -c Release --no-restore # 显式构建,避免重复恢复
- name: 打包NuGet包
continue-on-error: true # NuGet包可单独上传,不阻塞Release
run: |
$projects = @(
"GeneralUpdate.Bowl",
"GeneralUpdate.Core",
"GeneralUpdate.Differential",
"GeneralUpdate.Drivelution",
"GeneralUpdate.Extension"
)
$failed = $false
foreach ($project in $projects) {
Write-Host "=== 打包 $project ==="
& dotnet pack ./src/$project/$project.csproj `
-c Release `
-o ./nupkgs `
-p:Version='${{ steps.normalize.outputs.version }}' `
-p:PackageVersion='${{ steps.normalize.outputs.version }}'
if ($LASTEXITCODE -ne 0) {
Write-Host "!!! 警告: $project 打包时遇到可恢复错误 !!!"
$failed = $true
}
}
if ($failed) { Write-Host "部分包打包时有警告,但继续执行" }
shell: pwsh
- name: 登录 nuget.org (OIDC → 临时 API Key)
uses: NuGet/login@v1
id: login
with:
user: ${{ secrets.NUGET_USER }}
- name: 推送NuGet包到 nuget.org
continue-on-error: true # 即便推送失败也继续创建GitHub Release
run: |
$apiKey = '${{ steps.login.outputs.NUGET_API_KEY }}'
$nupkgs = Get-ChildItem ./nupkgs/*.nupkg | Where-Object { $_.Name -notlike '*.snupkg' }
foreach ($nupkg in $nupkgs) {
Write-Host "推送 $($nupkg.Name)..."
dotnet nuget push $nupkg.FullName `
--api-key $apiKey `
--source https://api.nuget.org/v3/index.json `
--skip-duplicate
}
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${{ steps.normalize.outputs.version }}
name: Release v${{ steps.normalize.outputs.version }}
body_path: changelog.md
files: ./nupkgs/*.nupkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}