From 6933d2799a720c6cf4d7b40bd179fd1a89d2262f Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Fri, 17 Apr 2026 19:54:58 +0800
Subject: [PATCH] =?UTF-8?q?ci(build):=20=E6=B7=BB=E5=8A=A0CI/CD=E5=B7=A5?=
=?UTF-8?q?=E4=BD=9C=E6=B5=81=E5=B9=B6=E4=BF=AE=E5=A4=8D=E5=8C=85=E4=BE=9D?=
=?UTF-8?q?=E8=B5=96=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 配置CI工作流支持PR时执行代码质量检查、构建和测试
- 设置发布工作流支持标签推送时自动打包发布到NuGet和GitHub Packages
- 修复源代码生成器项目的包依赖配置,统一使用GFramework.SourceGenerators.Common命名
- 配置多版本.NET SDK支持及相应的缓存策略
- 实现并行测试执行和统一的测试报告生成机制
- 添加安全扫描和代码质量检查集成
---
.github/workflows/ci.yml | 65 +++++++++----------
.github/workflows/publish.yml | 46 ++++++++++++-
.../GFramework.Core.SourceGenerators.csproj | 6 +-
3 files changed, 78 insertions(+), 39 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index defe6c71..1656d863 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -117,7 +117,7 @@ jobs:
# 执行NuGet包恢复操作
- name: Restore
- run: dotnet restore
+ run: dotnet restore GFramework.sln
# 恢复.NET本地工具
- name: Restore .NET tools
run: dotnet tool restore
@@ -142,49 +142,46 @@ jobs:
# 构建项目,使用Release配置且跳过恢复步骤
- name: Build
- run: dotnet build -c Release --no-restore
+ run: dotnet build GFramework.sln -c Release --no-restore
# 运行单元测试,输出TRX格式结果到TestResults目录
# 在同一个 step 中并发执行所有测试以加快速度
- name: Test All Projects
run: |
- dotnet test GFramework.Core.Tests \
- -c Release \
- --no-build \
- --logger "trx;LogFileName=core-$RANDOM.trx" \
- --results-directory TestResults &
+ set -euo pipefail
- dotnet test GFramework.Game.Tests \
- -c Release \
- --no-build \
- --logger "trx;LogFileName=game-$RANDOM.trx" \
- --results-directory TestResults &
+ test_projects=(
+ "GFramework.Core.Tests/GFramework.Core.Tests.csproj:core"
+ "GFramework.Game.Tests/GFramework.Game.Tests.csproj:game"
+ "GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj:sg"
+ "GFramework.Cqrs.Tests/GFramework.Cqrs.Tests.csproj:cqrs"
+ "GFramework.Ecs.Arch.Tests/GFramework.Ecs.Arch.Tests.csproj:ecs-arch"
+ "GFramework.Godot.Tests/GFramework.Godot.Tests.csproj:godot"
+ "GFramework.Godot.SourceGenerators.Tests/GFramework.Godot.SourceGenerators.Tests.csproj:godot-sg"
+ )
- dotnet test GFramework.SourceGenerators.Tests \
- -c Release \
- --no-build \
- --logger "trx;LogFileName=sg-$RANDOM.trx" \
- --results-directory TestResults &
+ pids=()
+ for entry in "${test_projects[@]}"; do
+ project="${entry%%:*}"
+ name="${entry##*:}"
- dotnet test GFramework.Cqrs.Tests \
- -c Release \
- --no-build \
- --logger "trx;LogFileName=cqrs-$RANDOM.trx" \
- --results-directory TestResults &
+ dotnet test "$project" \
+ -c Release \
+ --no-build \
+ --logger "trx;LogFileName=${name}-$RANDOM.trx" \
+ --results-directory TestResults &
- dotnet test GFramework.Ecs.Arch.Tests \
- -c Release \
- --no-build \
- --logger "trx;LogFileName=ecs-arch-$RANDOM.trx" \
- --results-directory TestResults &
+ pids+=("$!")
+ done
- dotnet test GFramework.Godot.Tests \
- -c Release \
- --no-build \
- --logger "trx;LogFileName=godot-$RANDOM.trx" \
- --results-directory TestResults &
- # 等待所有后台测试完成
- wait
+ failed=0
+ for pid in "${pids[@]}"; do
+ if ! wait "$pid"; then
+ failed=1
+ fi
+ done
+
+ exit "$failed"
- name: Generate CTRF report
run: |
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 0670c930..e1287f3e 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -52,7 +52,7 @@ jobs:
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
- name: Restore dependencies
- run: dotnet restore
+ run: dotnet restore GFramework.sln
# 从 GitHub 引用中提取标签版本。
# 提取逻辑:去除 refs/tags/ 前缀,然后去除 v/V 前缀。
@@ -71,7 +71,49 @@ jobs:
run: |
set -e
echo "Packing with version=${{ steps.tag_version.outputs.version }}"
- dotnet pack -c Release -o ./packages -p:PackageVersion=${{ steps.tag_version.outputs.version }} -p:IncludeSymbols=false
+ dotnet pack GFramework.sln \
+ -c Release \
+ --no-restore \
+ -o ./packages \
+ -p:PackageVersion=${{ steps.tag_version.outputs.version }} \
+ -p:IncludeSymbols=false
+
+ - name: Validate packed modules
+ run: |
+ set -euo pipefail
+
+ expected_packages=(
+ "GeWuYou.GFramework"
+ "GeWuYou.GFramework.Core"
+ "GeWuYou.GFramework.Core.Abstractions"
+ "GeWuYou.GFramework.Core.SourceGenerators"
+ "GeWuYou.GFramework.Cqrs"
+ "GeWuYou.GFramework.Cqrs.Abstractions"
+ "GeWuYou.GFramework.Cqrs.SourceGenerators"
+ "GeWuYou.GFramework.Ecs.Arch"
+ "GeWuYou.GFramework.Ecs.Arch.Abstractions"
+ "GeWuYou.GFramework.Game"
+ "GeWuYou.GFramework.Game.Abstractions"
+ "GeWuYou.GFramework.Game.SourceGenerators"
+ "GeWuYou.GFramework.Godot"
+ "GeWuYou.GFramework.Godot.SourceGenerators"
+ )
+
+ mapfile -t actual_packages < <(
+ find ./packages -maxdepth 1 -type f -name '*.nupkg' -printf '%f\n' \
+ | sed -E 's/\.[0-9][0-9A-Za-z.-]*\.nupkg$//' \
+ | sort -u
+ )
+
+ printf '%s\n' "${expected_packages[@]}" | sort > expected-packages.txt
+ printf '%s\n' "${actual_packages[@]}" | sort > actual-packages.txt
+
+ echo "Expected packages:"
+ cat expected-packages.txt
+ echo "Actual packages:"
+ cat actual-packages.txt
+
+ diff -u expected-packages.txt actual-packages.txt
- name: Show packages
run: ls -la ./packages || true
diff --git a/GFramework.Core.SourceGenerators/GFramework.Core.SourceGenerators.csproj b/GFramework.Core.SourceGenerators/GFramework.Core.SourceGenerators.csproj
index 72a2c200..c87ffe6c 100644
--- a/GFramework.Core.SourceGenerators/GFramework.Core.SourceGenerators.csproj
+++ b/GFramework.Core.SourceGenerators/GFramework.Core.SourceGenerators.csproj
@@ -52,7 +52,7 @@
PackagePath="analyzers/dotnet/cs"
Visible="false"/>
-
@@ -61,8 +61,8 @@
-
-
+
+