Skip to content

Commit badc3aa

Browse files
committed
Update dotnet-aot-check.yaml
1 parent ca228aa commit badc3aa

File tree

1 file changed

+29
-52
lines changed

1 file changed

+29
-52
lines changed
Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,38 @@
1-
name: dotnet-aot-check
1+
name: Check AOT Support
22

3-
on:
4-
pull_request:
5-
push:
3+
on: [push, pull_request]
64

75
jobs:
8-
aot-compile-check:
9-
runs-on: ${{ matrix.os }}
10-
strategy:
11-
matrix:
12-
# 预定义每个OS对应的runtime和shell,避开三元表达式
13-
include:
14-
- os: windows-latest
15-
runtime: win-x64
16-
shell: pwsh
17-
- os: ubuntu-latest
18-
runtime: linux-x64
19-
shell: bash
6+
check-aot:
7+
runs-on: windows-latest # 也可使用 ubuntu-latest 或 macos-latest
208

219
steps:
22-
# 步骤1:拉取代码(缩进6个空格,以下步骤统一)
23-
- name: Checkout code
24-
uses: actions/checkout@v4
10+
- uses: actions/checkout@v4
2511

26-
# 步骤2:安装.NET SDK(第23行对应这里的dotnet-version)
27-
- name: Setup .NET SDK
28-
uses: actions/setup-dotnet@v4
29-
with:
30-
dotnet-version: # 父级缩进10个空格
31-
- '8.0.x' # 数组项缩进12个空格(比父级多2个空格)
12+
- name: Setup .NET SDK
13+
uses: actions/setup-dotnet@v4
14+
with:
15+
dotnet-version: '9.0.x' # 需使用支持AOT的.NET版本(.NET 7+)
3216

33-
# 步骤3:恢复依赖
34-
- name: Restore dependencies
35-
run: dotnet restore ./src/c#/GeneralUpdate.sln
17+
- name: Restore dependencies
18+
run: dotnet restore ./src/c#/GeneralUpdate.sln
3619

37-
# 步骤4:AOT编译检测(用预定义的shell,无三元表达式)
38-
- name: Check AOT compilation
39-
shell: ${{ matrix.shell }}
40-
run: |
41-
dotnet publish ./src/c#/GeneralUpdate.Client/GeneralUpdate.Client.csproj \
42-
-c Release \
43-
-f net8.0 \
44-
-r ${{ matrix.runtime }} \
45-
--self-contained true \
46-
-p:PublishAot=true \
47-
-p:EnableCompilationRelaxations=false
48-
env:
49-
DOTNET_CLI_TELEMETRY_OPTOUT: 1
20+
- name: Check AOT compatibility
21+
run: |
22+
# 尝试以AOT模式发布项目(以控制台应用为例)
23+
dotnet publish ./src/c#/GeneralUpdate.Console/GeneralUpdate.Console.csproj \
24+
-c Release \
25+
-r win-x64 \ # 根据运行系统选择运行时标识符(如 linux-x64、osx-x64)
26+
-p:PublishAot=true \
27+
--self-contained true
28+
continue-on-error: true # 允许命令失败,后续通过日志判断结果
5029

51-
# 步骤5:验证AOT输出
52-
- name: Verify AOT output
53-
shell: pwsh
54-
run: |
55-
$publishDir = "./src/c#/GeneralUpdate.Client/bin/Release/net8.0/${{ matrix.runtime }}/publish"
56-
if ($env:RUNNER_OS -eq "Windows" -and -not (Test-Path "$publishDir/GeneralUpdate.Client.exe")) {
57-
throw "AOT executable not found for Windows: $publishDir/GeneralUpdate.Client.exe"
58-
}
59-
if ($env:RUNNER_OS -eq "Linux" -and -not (Test-Path "$publishDir/GeneralUpdate.Client")) {
60-
throw "AOT executable not found for Linux: $publishDir/GeneralUpdate.Client"
61-
}
30+
- name: Analyze result
31+
run: |
32+
# 检查上一步骤的退出码,0表示AOT编译成功,非0表示不支持
33+
if ($LASTEXITCODE -eq 0) {
34+
Write-Host "✅ 项目支持AOT编译"
35+
} else {
36+
Write-Host "❌ 项目不支持AOT编译,请检查错误日志"
37+
exit 1 # 若需要严格检测,可在此处让Workflow失败
38+
}

0 commit comments

Comments
 (0)