Repository navigation
595 lines (544 loc) · 28.8 KB
/
Copy pathpublish-commit.yml
File metadata and controls
595 lines (544 loc) · 28.8 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
name: publish/commit
on:
workflow_dispatch:
push:
branches:
- main
# 同一通道必须串行:多次推送并发跑会互相删除 / 覆盖同一个 release。
# commit 通道只关心「最新快照」,所以新推送直接取消仍在跑的旧构建。
concurrency:
group: publish-commit
cancel-in-progress: true
# 显式收敛 GITHUB_TOKEN 权限(对应 CodeQL: actions/missing-workflow-permissions)。
# 与已验证可用的 publish-release.yml 取同一组合 —— 这两个权限就是发布流程实际需要的全部:
# contents: write 创建/更新 release、上传资产(gh release create/upload)
# packages: read 从 GitHub Packages 还原基座库 CodeHub-FluentUI
# 仓库级默认是「读写全部」,这里收紧到最小集。
# 注:下载本工作流内其它 job 的 artifact 走 ACTIONS_RUNTIME_TOKEN,不需要额外权限。
permissions:
contents: write
packages: read
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
version_json: ${{ steps.meta.outputs.json }}
app_version: ${{ steps.meta.outputs.app_version }}
commit: ${{ steps.meta.outputs.commit_hash }}
steps:
- uses: actions/checkout@v7
- name: Generate Meta and JSON
id: meta
run: |
BASE_VERSION=$(cat ./assets/conf/version.txt | tr -d '[:space:]')
Y_FULL=$(TZ='Asia/Shanghai' date +'%Y')
MD=$(TZ='Asia/Shanghai' date +'%m%d')
HM=$(TZ='Asia/Shanghai' date +'%H%M')
FULL_TIMESTAMP="${Y_FULL}${MD}${HM}"
START_EPOCH=$(TZ='Asia/Shanghai' date -d "2026-07-10 00:00:00" +%s)
NOW_EPOCH=$(date +%s)
TOTAL_MINUTES=$(( (NOW_EPOCH - START_EPOCH) / 60 ))
TOTAL_DAYS=$(( TOTAL_MINUTES / 1440 ))
ELAPSED_HOURS=$(( (TOTAL_MINUTES % 1440) / 60 ))
ELAPSED_MINUTES=$(( TOTAL_MINUTES % 60 ))
APP_VERSION="0.${TOTAL_DAYS}.${ELAPSED_HOURS}.${ELAPSED_MINUTES}"
COMMIT_HASH=$(git rev-parse --short=6 HEAD)
BUILD_TIME=$(TZ='Asia/Shanghai' date -Iseconds)
VERSION_TITLE="build-commit-${APP_VERSION}-${{ github.run_id }}-${COMMIT_HASH}"
JSON_STRING="{\"type\":\"commit\",\"build-time\":\"${BUILD_TIME}\",\"action\":\"${{ github.run_id }}\",\"commit\":\"${COMMIT_HASH}\",\"version\":\"${BASE_VERSION}\",\"timestamp\":\"${FULL_TIMESTAMP}\",\"version_title\":\"${VERSION_TITLE}\"}"
echo "json=${JSON_STRING}" >> $GITHUB_OUTPUT
echo "app_version=${APP_VERSION}" >> $GITHUB_OUTPUT
echo "commit_hash=${COMMIT_HASH}" >> $GITHUB_OUTPUT
linux-package:
runs-on: ubuntu-22.04
needs: prepare
env:
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
MICROSOFT_CLIENT_ID: ${{ secrets.MICROSOFT_CLIENT_ID }}
LITTLESKIN_CLIENT_ID: ${{ secrets.LITTLESKIN_CLIENT_ID }}
GRAVITYCONE_UPTIME_API_KEY: ${{ secrets.GRAVITYCONE_UPTIME_API_KEY }}
PRE_MC_KEY: ${{ secrets.PRE_MC_KEY }}
REL_MC_KEY: ${{ secrets.REL_MC_KEY }}
strategy:
fail-fast: false
matrix:
include:
- kind: appimage
package_type: appimage
runtime: linux-x64
output: MChub.linux.x64.AppImage
- kind: deb
package_type: deb
runtime: linux-x64
output: MChub.linux.x64.deb
- kind: rpm
package_type: rpm
runtime: linux-x64
output: MChub.linux.x64.rpm
- kind: appimage
package_type: appimage
runtime: linux-arm64
output: MChub.linux.arm64.AppImage
- kind: deb
package_type: deb
runtime: linux-arm64
output: MChub.linux.arm64.deb
# rpm arm64 skipped: rpmbuild on x86_64 runner cannot cross-compile
# arm64 packages. Users on arm64 Linux should use the .deb or
# AppImage builds instead.
steps:
# 基座库 CodeHub-FluentUI 发布在 GitHub Packages。该源即使包是公开的也要求认证
# (实测匿名请求服务索引与包下载均 401),所以每个会还原的作业都要先配好凭据。
# 显式指定 bash:Windows runner 默认 PowerShell,续行符 \ 会被判为语法错误,
# 因此这里写成单行,三种系统下行为一致。
- name: Configure NuGet (GitHub Packages)
shell: bash
run: |-
dotnet nuget add source "https://nuget.pkg.github.com/hub-code-develop/index.json" --username "${{ github.actor }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name codehub-gh
- name: Checkout
uses: actions/checkout@v7
with:
submodules: "recursive"
- name: Update Submodules
run: |
git submodule update --init --recursive
git submodule foreach --recursive 'branch=$(git config -f "$toplevel/.gitmodules" --get "submodule.$name.branch" || echo main); git fetch origin "$branch" && git checkout -B "$branch" "origin/$branch"'
- name: Write CI Config
run: |
echo '${{ needs.prepare.outputs.version_json }}' > ./assets/conf/version-ci.txt
echo '${{ matrix.package_type }}' > ./assets/conf/package-type.txt
- name: Dependency
run: |
dotnet tool install -g KuiperZone.PupNet --version 1.8.0
sudo apt-get update && sudo apt-get install -y fuse rpm
- name: Build ${{ matrix.kind }} Package
run: |
cd ./assets/conf
pupnet --runtime ${{ matrix.runtime }} --kind ${{ matrix.kind }} -o ${{ matrix.output }} -y --app-version ${{ needs.prepare.outputs.app_version }}
- name: Upload Artifacts
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.runtime }}-${{ matrix.kind }}-artifacts
path: assets/conf/Deploy/OUT/${{ matrix.output }}
win-exe:
runs-on: windows-latest
needs: prepare
env:
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
MICROSOFT_CLIENT_ID: ${{ secrets.MICROSOFT_CLIENT_ID }}
LITTLESKIN_CLIENT_ID: ${{ secrets.LITTLESKIN_CLIENT_ID }}
GRAVITYCONE_UPTIME_API_KEY: ${{ secrets.GRAVITYCONE_UPTIME_API_KEY }}
PRE_MC_KEY: ${{ secrets.PRE_MC_KEY }}
REL_MC_KEY: ${{ secrets.REL_MC_KEY }}
strategy:
fail-fast: false
matrix:
include:
- runtime: win-x64
arch: x64
- runtime: win-arm64
arch: arm64
steps:
# 基座库 CodeHub-FluentUI 发布在 GitHub Packages。该源即使包是公开的也要求认证
# (实测匿名请求服务索引与包下载均 401),所以每个会还原的作业都要先配好凭据。
# 显式指定 bash:Windows runner 默认 PowerShell,续行符 \ 会被判为语法错误,
# 因此这里写成单行,三种系统下行为一致。
- name: Configure NuGet (GitHub Packages)
shell: bash
run: |-
dotnet nuget add source "https://nuget.pkg.github.com/hub-code-develop/index.json" --username "${{ github.actor }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name codehub-gh
- name: Checkout code
uses: actions/checkout@v7
with:
submodules: "recursive"
- name: Update Submodules
run: |
git submodule update --init --recursive
git submodule foreach --recursive 'branch=$(git config -f "$toplevel/.gitmodules" --get "submodule.$name.branch" || echo main); git fetch origin "$branch" && git checkout -B "$branch" "origin/$branch"'
shell: bash
- name: Write CI Config
run: |
echo '${{ needs.prepare.outputs.version_json }}' > ./assets/conf/version-ci.txt
echo 'portable' > ./assets/conf/package-type.txt
shell: bash
- name: Build & Package
shell: pwsh
run: |
cd ./src/MChub.Desktop
New-Item -ItemType Directory -Force -Path "../../dist"
dotnet restore -r ${{ matrix.runtime }}
dotnet publish -c Release -r ${{ matrix.runtime }} /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true /p:SelfContained=false /p:Version=${{ needs.prepare.outputs.app_version }} -o "../../dist" -p:DebugType=none -p:DebugSymbols=false
cd "../../dist"
Rename-Item -Path "MChub.Desktop.exe" -NewName "MChub.win.${{ matrix.arch }}.portable.exe" -Force
Compress-Archive -Path "MChub.win.${{ matrix.arch }}.portable.exe" -DestinationPath "../MChub.win.${{ matrix.arch }}.portable.zip" -Force
- name: Upload Artifacts
uses: actions/upload-artifact@v7
with:
name: win-exe-win.${{ matrix.arch }}-artifacts
path: ./MChub.*.zip
win-installer:
runs-on: windows-latest
needs: prepare
env:
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
MICROSOFT_CLIENT_ID: ${{ secrets.MICROSOFT_CLIENT_ID }}
LITTLESKIN_CLIENT_ID: ${{ secrets.LITTLESKIN_CLIENT_ID }}
GRAVITYCONE_UPTIME_API_KEY: ${{ secrets.GRAVITYCONE_UPTIME_API_KEY }}
PRE_MC_KEY: ${{ secrets.PRE_MC_KEY }}
REL_MC_KEY: ${{ secrets.REL_MC_KEY }}
strategy:
fail-fast: false
matrix:
include:
- runtime: win-x64
arch: x64
- runtime: win-arm64
arch: arm64
steps:
# 基座库 CodeHub-FluentUI 发布在 GitHub Packages。该源即使包是公开的也要求认证
# (实测匿名请求服务索引与包下载均 401),所以每个会还原的作业都要先配好凭据。
# 显式指定 bash:Windows runner 默认 PowerShell,续行符 \ 会被判为语法错误,
# 因此这里写成单行,三种系统下行为一致。
- name: Configure NuGet (GitHub Packages)
shell: bash
run: |-
dotnet nuget add source "https://nuget.pkg.github.com/hub-code-develop/index.json" --username "${{ github.actor }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name codehub-gh
- name: Checkout code
uses: actions/checkout@v7
with:
submodules: "recursive"
- name: Update Submodules
run: |
git submodule update --init --recursive
git submodule foreach --recursive 'branch=$(git config -f "$toplevel/.gitmodules" --get "submodule.$name.branch" || echo main); git fetch origin "$branch" && git checkout -B "$branch" "origin/$branch"'
shell: bash
- name: Dependencies
run: |
choco install innosetup -y
dotnet tool install -g KuiperZone.PupNet --version 1.8.0
- name: Chinesize-InnoSetup
run: Copy-Item "./assets/conf/ChineseSimplified.isl" "C:\Program Files (x86)\Inno Setup 6\Default.isl" -Force
- name: Write CI Config
run: |
echo '${{ needs.prepare.outputs.version_json }}' > ./assets/conf/version-ci.txt
echo 'installer' > ./assets/conf/package-type.txt
shell: bash
- name: Build & Package
shell: pwsh
run: |
cd ./assets/conf
pupnet -r ${{ matrix.runtime }} -k setup -y -o MChub.win.${{ matrix.arch }}.installer.exe --app-version ${{ needs.prepare.outputs.app_version }}
../../scripts/configure-windows-installer.ps1 -Runtime ${{ matrix.runtime }}
Compress-Archive -Path "Deploy/OUT/MChub.win.${{ matrix.arch }}.installer.exe" -DestinationPath "Deploy/OUT/MChub.win.${{ matrix.arch }}.installer.zip" -Force
- name: Upload Artifacts
uses: actions/upload-artifact@v7
with:
name: win-installer-win.${{ matrix.arch }}-artifacts
path: assets/conf/Deploy/OUT/MChub.win.*.installer.zip
# 基岩版在 macOS 上没有原生客户端,靠 Wine(WineGDK) + xodus-service 跑 Windows GDK 版;
# 运行时由可复用的 bedrock-macos-runtime.yml 构建,再内嵌进 .app。
bedrock-macos-runtime:
name: bedrock-macos-runtime
uses: ./.github/workflows/bedrock-macos-runtime.yml
mac-dmg:
runs-on: macos-latest
needs: [prepare, bedrock-macos-runtime]
env:
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }}
MICROSOFT_CLIENT_ID: ${{ secrets.MICROSOFT_CLIENT_ID }}
LITTLESKIN_CLIENT_ID: ${{ secrets.LITTLESKIN_CLIENT_ID }}
GRAVITYCONE_UPTIME_API_KEY: ${{ secrets.GRAVITYCONE_UPTIME_API_KEY }}
PRE_MC_KEY: ${{ secrets.PRE_MC_KEY }}
REL_MC_KEY: ${{ secrets.REL_MC_KEY }}
strategy:
fail-fast: false
matrix:
rid: [osx-x64, osx-arm64]
include:
- rid: osx-x64
dmg_arch: x64
- rid: osx-arm64
dmg_arch: arm64
steps:
# 基座库 CodeHub-FluentUI 发布在 GitHub Packages。该源即使包是公开的也要求认证
# (实测匿名请求服务索引与包下载均 401),所以每个会还原的作业都要先配好凭据。
# 显式指定 bash:Windows runner 默认 PowerShell,续行符 \ 会被判为语法错误,
# 因此这里写成单行,三种系统下行为一致。
- name: Configure NuGet (GitHub Packages)
shell: bash
run: |-
dotnet nuget add source "https://nuget.pkg.github.com/hub-code-develop/index.json" --username "${{ github.actor }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name codehub-gh
- name: Checkout
uses: actions/checkout@v7
with:
submodules: "recursive"
# 编译用官方 SDK,CodeNet 只作为「运行时库来源」(与 publish-release.yml 同一套做法)。
# 背景:2026-11 把三家组合都实测过一遍 ——
# macos-latest(arm64) + CodeNet x64(Rosetta) → restore 段错误,bundle 三次全崩
# macos-latest(arm64) + CodeNet arm64(原生) → bundle 崩两次,第三次 csc 139
# macos-15-intel(x86_64) + CodeNet x64(原生) → restore 通过,bundle 三次段错误
# macos-latest(arm64) + 官方 SDK 10.0.400 → 构建成功
# 崩的是 CodeNet 那套编译器本身,与 Rosetta / runner 架构无关。
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.400
- name: Fetch CodeNet runtime (signalfix 原生库)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
CODENET_VER="10.0.400"
# arm64 包解压后顶层目录名仍是 dotnet11x64(历史遗留),内部二进制才是对应架构。
if [ "${{ matrix.dmg_arch }}" = "arm64" ]; then
ASSET="dotnet-codenet-osx-arm64-fixed.tar.gz"
else
ASSET="dotnet-codenet-osx-x64.tar.gz"
fi
DEST="$RUNNER_TEMP/codenet-runtime"
mkdir -p "$DEST"
echo "下载 CodeNet ${ASSET} 仅用于取 signalfix 原生库 ..."
gh release download "sdk-v${CODENET_VER}" -R Open-code-Studio/CodeNet -p "$ASSET" -D "$DEST"
tar xzf "$DEST/$ASSET" -C "$DEST"
LIBSRC=$(find "$DEST" -maxdepth 5 -type d -name "Microsoft.NETCore.App" | head -1)
echo "CodeNet 运行时目录: $LIBSRC"
ls "$LIBSRC"
# 取其中版本号最大的目录,作为后面固定 RuntimeFrameworkVersion 的依据:
# 官方 SDK 默认带的是更新的补丁版(如 10.0.14),CodeNet 只有它自己那一版,
# 不固定住的话 publish 会拉到官方包,signalfix 那四个 dylib 就对不上了。
CODENET_RT=$(ls "$LIBSRC" | sort -V | tail -1)
echo "CodeNet 运行时版本: $CODENET_RT"
echo "CODENET_LIBS=$LIBSRC" >> "$GITHUB_ENV"
echo "CODENET_RT=$CODENET_RT" >> "$GITHUB_ENV"
- name: Update Submodules
run: |
git submodule update --init --recursive
git submodule foreach --recursive 'branch=$(git config -f "$toplevel/.gitmodules" --get "submodule.$name.branch" || echo main); git fetch origin "$branch" && git checkout -B "$branch" "origin/$branch"'
- name: Write CI Config
run: |
echo '${{ needs.prepare.outputs.version_json }}' > ./assets/conf/version-ci.txt
echo 'app' > ./assets/conf/package-type.txt
- name: Download Bedrock native components
uses: actions/download-artifact@v7
with:
name: mcbe-macos-native-components
path: .native-components
- name: Install Bedrock native components
run: |
# MacOS 工程把这两个 DLL 内嵌为 EmbeddedResource(BundleApp 时读取),
# 必须在构建 App 之前就位;否则内嵌的仍是仓库里陈旧的 Portal 构建产物。
cp .native-components/MChub.Preload.dll ./src/MChub.Bedrock.Preload/MChub.Preload.dll
cp .native-components/MChub.Bootstrap.dll ./src/MChub.Bedrock.Bootstrap/MChub.Bootstrap.dll
ls -l ./src/MChub.Bedrock.Preload/MChub.Preload.dll ./src/MChub.Bedrock.Bootstrap/MChub.Bootstrap.dll
- name: Build macOS App
# 编译用官方 SDK(上面已实测:CodeNet SDK 的编译器在 CI 的 mac 宿主上必崩)。
# 仍保留 -m:1 + 禁用共享编译、关掉 MSBuild server:历史上班上的
# MSB4166 "Child node exited prematurely"
# 就是多进程 MSBuild 引起的,单进程最稳,代价只是慢一点。
# restore 保留重试:NuGet 偶发超时不算构建失败。
env:
DOTNET_CLI_USE_MSBUILD_SERVER: "0"
MSBUILDDISABLENODEREUSE: "1"
run: |
cd ./src/MChub.Desktop
run_with_timeout() {
local label="$1"; shift
for attempt in 1 2 3; do
echo "== $label attempt $attempt =="
dotnet "$@" &
local pid=$!
( sleep 900; kill -9 "$pid" 2>/dev/null ) &
local killer=$!
# GitHub 默认 shell 带 -e,wait 直接返回非 0 会终止脚本,导致重试分支永远不执行
local rc=0
wait "$pid" || rc=$?
kill "$killer" 2>/dev/null || true
if [ "$rc" -eq 0 ]; then
echo "== $label OK =="
return 0
fi
echo "== $label failed (rc=$rc), retrying =="
pkill -9 dotnet 2>/dev/null || true
sleep 5
done
echo "== $label gave up after 3 attempts =="
return 1
}
run_with_timeout restore restore -r ${{ matrix.rid }} -p:RuntimeFrameworkVersion="$CODENET_RT" -m:1 /p:UseSharedCompilation=false
run_with_timeout bundle msbuild -t:BundleApp -p:RuntimeIdentifier=${{ matrix.rid }} -property:Configuration=Release -p:SelfContained=true -p:RuntimeFrameworkVersion="$CODENET_RT" -m:1 /p:UseSharedCompilation=false
# macOS 27 的 EXC_GUARD 会让原版运行时的 Mach exception 路径被 SIGKILL(137),
# CodeNet 的 signalfix 版本把这条路径换成 signal-based SEH。
# 编译阶段用不了 CodeNet 的 SDK,但产物里的原生库可以直接换成它的。
# 只有运行时版本完全一致(App 的 runtimeconfig 与 CodeNet 的 shared 目录同名)
# 才替换,避免 CoreCLR 与 CoreLib 版本错配把 App 搞坏。
- name: Overlay signalfix runtime
run: |
set -euo pipefail
APP="./src/MChub.Desktop/bin/Release/net10.0/${{ matrix.rid }}/publish/MChub.app"
APPRT=$(python3 -c "import json;print(json.load(open('$APP/Contents/MacOS/MChub.Desktop.runtimeconfig.json'))['runtimeOptions']['includedFrameworks'][0]['version'])")
echo "App 运行时版本: $APPRT"
if [ ! -d "$CODENET_LIBS/$APPRT" ]; then
# 以前这里是 ::warning:: 然后 exit 0 —— 结果是 macOS 包带着官方运行时发出去,
# 在 macOS 27 上一启动就是 "Failed to create CoreCLR, HRESULT: 0x8007000C"。
# 宁可这次构建失败,也不能再静默产出打不开的包。
echo "::error::CodeNet 没有 $APPRT 版本的运行时(只有 $(ls "$CODENET_LIBS" | tr '\n' ' '));官方运行时在 macOS 27 上会被 EXC_GUARD 打死,不能跳过 signalfix 叠加"
exit 1
fi
echo "CodeNet 运行时版本匹配,开始替换原生库"
for f in libcoreclr.dylib libclrjit.dylib libclrgc.dylib libclrgcexp.dylib; do
src="$CODENET_LIBS/$APPRT/$f"; dst="$APP/Contents/MacOS/$f"
if [ -f "$src" ] && [ -f "$dst" ]; then
before=$(stat -f%z "$dst")
cp -f "$src" "$dst"
chmod 755 "$dst"
echo " $f: $before -> $(stat -f%z "$dst")"
else
echo " 跳过 $f(源或目标不存在)"
fi
done
# 复核:核心四个库必须与 CodeNet 的同版本文件逐字节一致,否则等于没换。
for f in libcoreclr.dylib libclrjit.dylib libclrgc.dylib libclrgcexp.dylib; do
src="$CODENET_LIBS/$APPRT/$f"; dst="$APP/Contents/MacOS/$f"
[ -f "$src" ] && [ -f "$dst" ] || continue
if ! cmp -s "$src" "$dst"; then
echo "::error::$f 与 CodeNet 版本不一致,signalfix 未生效"
exit 1
fi
done
echo "signalfix 运行时已生效(libcoreclr 大小 $(stat -f%z "$APP/Contents/MacOS/libcoreclr.dylib"))"
# 签名不在这里做:后面塞完 Bedrock 运行时、改完 Info.plist 有统一的整包重签步骤
- name: Download Bedrock macOS runtime
uses: actions/download-artifact@v7
with:
name: mcbe-macos-runtime
path: .runtime
- name: Embed Bedrock macOS runtime
run: |
APP="./src/MChub.Desktop/bin/Release/net10.0/${{ matrix.rid }}/publish/MChub.app"
mkdir -p "$APP/Contents/MacOS/mcbe-macos"
# MChub.Bedrock.MacOS 在 AppContext.BaseDirectory/mcbe-macos 下探测运行时。
cp -R ./.runtime/. "$APP/Contents/MacOS/mcbe-macos/"
# 工件往返会丢失可执行位。ntdll.so 实际 exec 的是 unix 侧 loader
# (lib/wine/x86_64-unix/wine),缺 x 位时报 "could not exec the wine loader"。
chmod +x "$APP/Contents/MacOS/mcbe-macos/wine/bin/"* || true
chmod +x "$APP/Contents/MacOS/mcbe-macos/wine/lib/wine/x86_64-unix/wine"
chmod +x "$APP/Contents/MacOS/mcbe-macos/xodus/xodus-service"
ls -l "$APP/Contents/MacOS/mcbe-macos"
# DotNet.Bundle 不支持 CFBundleURLTypes,mchub:// 协议声明在打包后写入 Info.plist
- name: Declare mchub URL Scheme
run: |
PLIST="./src/MChub.Desktop/bin/Release/net10.0/${{ matrix.rid }}/publish/MChub.app/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLName string hub.code.mchub" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLRole string Viewer" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "$PLIST"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string mchub" "$PLIST"
# 打包前 MChub.app 只带着 apphost 的 ad-hoc 签名(.NET/DotNet.Bundle 自动施加)。
# 上面又往 Contents/MacOS 塞了 Bedrock 运行时、并用 PlistBuddy 改写了 Info.plist,
# bundle 级签名与内容因此不一致 —— codesign --verify 会报
# "code has no resources but signature indicates they must be present"
# 这种包在 Gatekeeper 开启的机器上会被拒(本机因 Gatekeeper 已关而看不出来)。
# 所以必须在 ditto / 建 DMG / pkgbuild 之前整包重签一次。
# 用 ad-hoc(-):不需要证书、不需要付费开发者账号,但能保证签名一致,
# 并满足 Apple Silicon「arm64 二进制必须带签名」的硬要求。
# 注意:ad-hoc 不等于公证 —— 用户从浏览器下载后首次打开仍需右键→打开。
- name: Sign app bundle (ad-hoc)
run: |
set -euo pipefail
APP="./src/MChub.Desktop/bin/Release/net10.0/${{ matrix.rid }}/publish/MChub.app"
VULKAN_DIR="$APP/Contents/MacOS/mcbe-macos/render/vulkan"
# macOS 把 ".d" 目录当成 bundle,codesign --deep 扫到
# .../render/vulkan/icd.d
# 会直接以 "bundle format unrecognized, invalid, or unsuitable" 失败。
# 绕过:真实目录留在 icd_d,用符号链接 icd.d 指回去 ——
# codesign 不跟随符号链接(因此跳过),而运行时路径
# ".../vulkan/icd.d/MoltenVK_icd.json" 仍能解析(实测可读)。
# 这与目录名无关:Vulkan 的 ICD 是由环境变量 VK_ICD_FILENAMES / VK_DRIVER_FILES
# 指向该 JSON 文件来定位的(见 MChub.Bedrock.MacOS/Runtime/WineEnvironment.cs)。
# 幂等;符号链接经 ditto 打包往返后仍保留(实测解包后 codesign --verify 通过)。
if [ -d "$VULKAN_DIR/icd.d" ] && [ ! -L "$VULKAN_DIR/icd.d" ]; then
mv "$VULKAN_DIR/icd.d" "$VULKAN_DIR/icd_d"
ln -s icd_d "$VULKAN_DIR/icd.d"
echo "已把 icd.d 换成符号链接(codesign --deep 不跟随符号链接)"
fi
# --force 覆盖 apphost 的旧 adhoc 签名;--deep 递归处理嵌套代码(含数百个托管 dll)
codesign --force --deep --sign - "$APP"
# 自检:刚签完必须校验通过,否则不要把签名坏的包发出去
codesign --verify --deep --verbose=2 "$APP"
codesign -dv "$APP" 2>&1 | grep -E "Identifier=|Signature=|Sealed" || true
- name: Package APP to ZIP
run: |
cd ./src/MChub.Desktop/bin/Release/net10.0/${{ matrix.rid }}/publish/
/usr/bin/ditto -c -k --keepParent MChub.app ../../../../../../../MChub.osx.mac.${{ matrix.dmg_arch }}.app.zip
# macOS Runner 预装的 aws/tap 未受信任,会导致 brew 输出警告,构建 DMG 前先移除
- name: Untap Untrusted Homebrew Taps
run: brew untap aws/tap || true
- name: Build DMG
uses: L-Super/create-dmg-actions@v1.1.0
with:
dmg_name: "MChub.osx.mac.${{ matrix.dmg_arch }}"
src_dir: "./src/MChub.Desktop/bin/Release/net10.0/${{ matrix.rid }}/publish/MChub.app"
- name: Build PKG
run: |
pkgbuild \
--root "./src/MChub.Desktop/bin/Release/net10.0/${{ matrix.rid }}/publish/MChub.app" \
--install-location "/Applications/MChub.app" \
--identifier "hub.code.MChub" \
--version "${{ needs.prepare.outputs.app_version }}" \
--timestamp \
"MChub.osx.mac.${{ matrix.dmg_arch }}.pkg"
- name: Upload Artifacts
uses: actions/upload-artifact@v7
with:
name: osx-${{ matrix.dmg_arch }}-artifacts
path: |
./MChub.osx.mac.${{ matrix.dmg_arch }}.dmg
./MChub.osx.mac.${{ matrix.dmg_arch }}.app.zip
./MChub.osx.mac.${{ matrix.dmg_arch }}.pkg
publish:
needs: [prepare, linux-package, win-exe, win-installer, mac-dmg]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Download All Artifacts
uses: actions/download-artifact@v8
with:
path: ./MChub.Release/
merge-multiple: true
- name: List Files
run: ls -la ./MChub.Release/
- name: Generate Changelog
run: |
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
bash .github/scripts/generate-changelog.sh "$REPO_URL" > RELEASE_CHANGELOG.md
if [ ! -s RELEASE_CHANGELOG.md ] || [ "$(wc -l < RELEASE_CHANGELOG.md)" -le 1 ]; then
echo "自上一个正式版以来没有新的提交" > RELEASE_CHANGELOG.md
fi
cat RELEASE_CHANGELOG.md
# ⚠ 不要「先删除旧 release 再重建」:那样在"已删、未建"的窗口里
# GET /releases/tags/publish-commit 会 404 —— 客户端更新检查会直接弹
# 「网络请求错误: 404」。action-gh-release 对**已存在的 tag** 是"更新"语义,
# 原地覆盖资产即可,全程保持 release 可用。
# 代价:tag 指针不再随构建移动 —— 对 commit 通道无影响,版本识别看
# release 标题里的 run_id + commit 短哈希。
- name: Publish Release
uses: softprops/action-gh-release@v3
with:
tag_name: publish-commit
name: "build-commit-${{ needs.prepare.outputs.app_version }}-${{ github.run_id }}-${{ needs.prepare.outputs.commit }}"
target_commitish: ${{ github.sha }}
prerelease: true
body_path: RELEASE_CHANGELOG.md
files: |
./MChub.Release/*.dmg
./MChub.Release/*.zip
./MChub.Release/*.pkg
./MChub.Release/*.AppImage
./MChub.Release/*.deb
./MChub.Release/*.rpm