Repository navigation
229 lines (208 loc) · 8.94 KB
/
Copy pathrelease.yml
File metadata and controls
229 lines (208 loc) · 8.94 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
name: release
# 推送 v* 标签发布 CodeWF.Toolkit 演示应用全平台包(5 个 RID):
# 全平台 NativeAOT(完整反射元数据保全 Prism/DryIoc、Dock、Magick.NET);
# Windows 出 Inno Setup 安装器,Linux 出 deb,macOS 出 dmg,均附 sha256。
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: '版本号(不含 v),例如 1.0.0.3'
required: true
type: string
permissions:
contents: write
jobs:
publish:
name: 发布 ${{ matrix.rid }}
strategy:
fail-fast: false
matrix:
include:
- rid: win-x64
os: windows-latest
- rid: linux-x64
os: ubuntu-latest
- rid: linux-arm64
os: ubuntu-24.04-arm
- rid: osx-x64
os: macos-15-intel
- rid: osx-arm64
os: macos-14
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: 安装 .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: 计算版本号
id: version
shell: pwsh
run: |
if ('${{ github.event_name }}' -eq 'workflow_dispatch') {
$version = '${{ inputs.version }}'.TrimStart('v', 'V')
} else {
$version = '${{ github.ref_name }}'.TrimStart('v', 'V')
}
"APP_VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
Write-Host "版本:$version"
- name: 安装 NativeAOT 依赖 (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y clang zlib1g-dev
- name: 发布(NativeAOT)
shell: pwsh
run: pwsh scripts/publish_toolkit_demo.ps1 -RuntimeIdentifier '${{ matrix.rid }}' -Version $env:APP_VERSION
- name: 验证正式 Windows 原生产物
if: runner.os == 'Windows'
shell: pwsh
run: |
$directory = Join-Path $env:RUNNER_TEMP ('demo-runtime-' + [guid]::NewGuid().ToString('N'))
$start = [Diagnostics.ProcessStartInfo]::new((Resolve-Path './artifacts/publish/win-x64/CodeWF.Toolkit.Demo.Avalonia/CodeWF.Toolkit.Demo.Avalonia.exe').Path)
$start.UseShellExecute = $false
$start.CreateNoWindow = $true
$start.ArgumentList.Add('--verify-runtime')
$start.ArgumentList.Add($directory)
$process = [Diagnostics.Process]::Start($start)
if (-not $process.WaitForExit(30000)) { throw 'Native runtime verification timed out.' }
if ($process.ExitCode -ne 0) { throw "Native runtime verification failed: $($process.ExitCode)" }
$result = Get-Content -LiteralPath (Join-Path $directory 'runtime-verification.txt') -Raw
if ($result -notmatch '^NativeAOT runtime verification passed;') { throw 'Native runtime evidence is missing.' }
Write-Output $result
- name: 打包 Linux deb + sha256
if: startsWith(matrix.rid, 'linux-')
shell: pwsh
run: pwsh scripts/package_linux_deb.ps1 -RuntimeIdentifier '${{ matrix.rid }}' -Version $env:APP_VERSION -Force
- name: 打包 macOS dmg + sha256
if: startsWith(matrix.rid, 'osx-')
shell: bash
run: |
chmod +x scripts/package_macos.sh
./scripts/package_macos.sh ${{ matrix.rid }}
- name: 收集 macOS dmg 到发布目录
if: startsWith(matrix.rid, 'osx-')
shell: pwsh
run: |
New-Item -ItemType Directory -Path artifacts/release -Force | Out-Null
Copy-Item -Path "artifacts/macos/*.dmg" -Destination artifacts/release/ -Force
Copy-Item -Path "artifacts/macos/*.dmg.sha256" -Destination artifacts/release/ -Force
Get-ChildItem artifacts/release | ForEach-Object { Write-Host $_.Name }
- name: 构建 Windows 安装包
if: matrix.rid == 'win-x64'
uses: Minionguyjpro/Inno-Setup-Action@v1.2.2
with:
path: scripts/CodeWF.Toolkit.Demo.iss
options: >-
/DAppVersion=${{ env.APP_VERSION }}
/DSourceDir=${{ github.workspace }}\artifacts\publish\win-x64\CodeWF.Toolkit.Demo.Avalonia
/DOutputDir=${{ github.workspace }}\artifacts\release
- name: 计算安装包 SHA-256
if: matrix.rid == 'win-x64'
shell: pwsh
run: |
$installerName = "CodeWF.Toolkit.Demo-v$env:APP_VERSION-win-x64-setup.exe"
$installerPath = Join-Path "artifacts/release" $installerName
if (-not (Test-Path -LiteralPath $installerPath -PathType Leaf)) {
throw "Installer was not produced: $installerPath"
}
$sha = (Get-FileHash -LiteralPath $installerPath -Algorithm SHA256).Hash.ToLowerInvariant()
"$sha $installerName" | Set-Content -LiteralPath "$installerPath.sha256" -Encoding ASCII
- name: 上传构建产物
uses: actions/upload-artifact@v4
with:
name: CodeWF.Toolkit.Demo-${{ matrix.rid }}
path: artifacts/release/*
if-no-files-found: error
release:
name: 创建 GitHub Release
needs: publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 下载构建产物
uses: actions/download-artifact@v4
with:
pattern: CodeWF.Toolkit.Demo-*
path: artifacts/release
merge-multiple: true
- name: 计算版本号
id: version
shell: pwsh
run: |
if ('${{ github.event_name }}' -eq 'workflow_dispatch') {
$version = '${{ inputs.version }}'.TrimStart('v', 'V')
$tagName = "v$version"
} else {
# 沿用被推送的原始标签,避免额外创建新标签。
$tagName = '${{ github.ref_name }}'
$version = $tagName.TrimStart('v', 'V')
}
"version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
"tag_name=$tagName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8
- name: 校验五平台安装包与 SHA-256
shell: pwsh
run: ./scripts/verify_release_installers.ps1 -Version '${{ steps.version.outputs.version }}'
- name: 准备发布说明
shell: pwsh
env:
VERSION: ${{ steps.version.outputs.version }}
TAG_NAME: ${{ steps.version.outputs.tag_name }}
run: |
# 优先使用版本说明,其次使用更新日志,最后回退到附注 tag。
$curated = ".github/release-notes/v$env:VERSION.md"
$bodyPath = "artifacts/release-body.md"
New-Item -ItemType Directory -Path (Split-Path -Parent $bodyPath) -Force | Out-Null
if (Test-Path -LiteralPath $curated -PathType Leaf) {
Copy-Item -LiteralPath $curated -Destination $bodyPath -Force
Write-Host "使用发布说明:$curated"
}
else {
$updateLog = "UpdateLog.md"
$body = New-Object System.Collections.Generic.List[string]
if (Test-Path -LiteralPath $updateLog -PathType Leaf) {
$lines = Get-Content -LiteralPath $updateLog -Encoding UTF8
$capture = $false
foreach ($line in $lines) {
if ($line -match '^#+\s.*v?' + [regex]::Escape($env:VERSION) + '\b') {
$capture = $true
$body.Add($line)
continue
}
if ($capture -and $line -match '^#+\s') { break }
if ($capture) { $body.Add($line) }
}
}
if ($body.Count -gt 0) {
$body | Set-Content -LiteralPath $bodyPath -Encoding utf8
Write-Host "使用 UpdateLog 段落作为发布说明。"
}
else {
git fetch --quiet --tags origin 2>$null
$tagMessage = git tag -l "$env:TAG_NAME" --format='%(contents)'
if (-not [string]::IsNullOrWhiteSpace($tagMessage)) {
$tagMessage | Set-Content -LiteralPath $bodyPath -Encoding utf8
Write-Host "使用附注 tag 说明作为发布说明。"
}
else {
"CodeWF.Toolkit v$env:VERSION" | Set-Content -LiteralPath $bodyPath -Encoding utf8
Write-Host "未找到版本说明,将只使用自动生成的变更列表。"
}
}
}
- name: 创建 GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag_name }}
name: CodeWF.Toolkit v${{ steps.version.outputs.version }}
body_path: artifacts/release-body.md
generate_release_notes: true
files: |
artifacts/release/*.deb
artifacts/release/*.dmg
artifacts/release/*.exe
artifacts/release/*.sha256