GeWuYou bba589a853 docs(config): 添加游戏内容配置系统完整文档
- 新增 CI/CD 工作流配置文件,集成代码质量检查、安全扫描和构建测试
- 详细介绍配置系统架构,包括 YAML 源文件、JSON Schema 结构描述和运行时只读查询
- 提供完整的目录结构推荐和 Schema/JSON 示例配置
- 包含项目接入模板,涵盖 csproj 配置、启动帮助器和运行时读取模板
- 说明运行时校验行为,支持必填字段、类型匹配、数值范围等校验规则
- 介绍开发期热重载功能,支持配置文件变更自动刷新
- 详述生成器接入约定,包括配置类型、表包装和注册辅助生成
- 提供 VS Code 工具使用指南,支持配置浏览、表单编辑和批量操作
- 说明当前系统限制和未来发展规划,明确适用场景
2026-04-06 21:19:49 +08:00

225 lines
6.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# CI/CD工作流配置构建和测试.NET项目
# 该工作流在push到main/master分支或创建pull request时触发
name: CI - Build & Test
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
permissions:
contents: read
security-events: write
jobs:
# 代码质量检查 job并行执行不阻塞构建
code-quality:
name: Code Quality & Security
runs-on: ubuntu-latest
steps:
# 检出源代码设置fetch-depth为0以获取完整的git历史
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
# 校验C#命名空间与源码目录是否符合命名规范
- name: Validate C# naming
run: bash scripts/validate-csharp-naming.sh
# 缓存MegaLinter
- name: Cache MegaLinter
uses: actions/cache@v5
with:
path: ~/.cache/megalinter
key: ${{ runner.os }}-megalinter-v9
restore-keys: |
${{ runner.os }}-megalinter-
# MegaLinter扫描步骤
# 执行代码质量检查和安全扫描生成SARIF格式报告
- name: MegaLinter
uses: oxsecurity/megalinter@v9.4.0
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FAIL_ON_ERROR: ${{ github.ref == 'refs/heads/main' }}
# 上传SARIF格式的安全和代码质量问题报告到GitHub安全中心
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: megalinter-reports/sarif
# 缓存TruffleHog
- name: Cache TruffleHog
uses: actions/cache@v5
with:
path: ~/.cache/trufflehog
key: ${{ runner.os }}-trufflehog
# TruffleHog OSS 扫描步骤
# 使用 TruffleHog 工具扫描代码库中的敏感信息泄露如API密钥、密码等
# 该步骤会比较基础分支和当前提交之间的差异,检测新增内容中是否包含敏感数据
- name: TruffleHog OSS
uses: trufflesecurity/trufflehog@v3.94.2
with:
# 扫描路径,. 表示扫描整个仓库
path: .
# 基础提交哈希,用于与当前提交进行比较
base: ${{ github.event.before }}
# 当前提交哈希,作为扫描的目标版本
head: ${{ github.sha }}
# 构建和测试 job并行执行
build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
# 检出源代码
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
# 安装和配置.NET SDK版本
- name: Setup .NET 8
uses: actions/setup-dotnet@v5
with:
dotnet-version: 8.0.x
- name: Setup .NET 9
uses: actions/setup-dotnet@v5
with:
dotnet-version: 9.0.x
- name: Setup .NET 10
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
# 配置NuGet包缓存以加速后续构建
- name: Cache NuGet packages
uses: actions/cache@v5
with:
path: |
~/.nuget/packages
~/.local/share/NuGet
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/nuget.config') }}
# 配置.NET本地工具缓存以加速后续构建
- name: Cache dotnet tools
uses: actions/cache@v5
with:
path: ~/.dotnet/tools
key: ${{ runner.os }}-dotnet-tools-${{ hashFiles('.config/dotnet-tools.json') }}
# 执行NuGet包恢复操作
- name: Restore
run: dotnet restore
# 恢复.NET本地工具
- name: Restore .NET tools
run: dotnet tool restore
- name: Setup Node.js 20
uses: actions/setup-node@v5
with:
node-version: 20
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.15
- name: Install config tool dependencies
working-directory: tools/gframework-config-tool
run: bun install
- name: Run config tool tests
working-directory: tools/gframework-config-tool
run: bun run test
# 构建项目使用Release配置且跳过恢复步骤
- name: Build
run: dotnet build -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 &
dotnet test GFramework.Game.Tests \
-c Release \
--no-build \
--logger "trx;LogFileName=game-$RANDOM.trx" \
--results-directory TestResults &
dotnet test GFramework.SourceGenerators.Tests \
-c Release \
--no-build \
--logger "trx;LogFileName=sg-$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 &
dotnet test GFramework.Godot.Tests \
-c Release \
--no-build \
--logger "trx;LogFileName=godot-$RANDOM.trx" \
--results-directory TestResults &
# 等待所有后台测试完成
wait
- name: Generate CTRF report
run: |
mkdir -p ctrf
for trx in TestResults/*.trx; do
name=$(basename "$trx" .trx)
echo "Processing $trx -> ctrf/$name.json"
dotnet tool run DotnetCtrfJsonReporter \
-p "$trx" \
-t nunit \
-d ctrf \
-f "$name.json"
done
# 生成并发布测试报告,无论测试成功或失败都会执行
- name: Test Report
uses: dorny/test-reporter@v3
if: always()
with:
name: .NET Test Results
path: TestResults/*.trx
reporter: dotnet-trx
- name: Publish Test Report
uses: ctrf-io/github-test-reporter@v1
with:
report-path: './ctrf/*.json'
github-report: true
pull-request-report: true
summary-delta-report: true
insights-report: true
flaky-rate-report: true
fail-rate-report: true
slowest-report: true
upload-artifact: true
fetch-previous-results: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: always()