Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/functional-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# 仅运行独立逻辑测试,不构建或发布 SLDataAPI.dll。
# 不下载游戏程序集、LabAPI、Unity,不使用签名密钥或真实 token。
# 本仓库的 Actions 策略只允许 DNTOF 拥有的 action,因此这里不用 actions/*。
# 可下载的 TRX 制品要等所有者允许官方 artifact action 之后才能保留。
name: 功能逻辑测试

on:
push:
pull_request:
workflow_dispatch:

permissions:
contents: read

concurrency:
group: functional-tests-${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

env:
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
DOTNET_NOLOGO: "1"
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1"

jobs:
test:
name: ${{ matrix.suite }}
runs-on: ubuntu-24.04
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
suite: [Auth, Features, Update, WebDav]
steps:
- name: 检出源码
env:
REPOSITORY: ${{ github.repository }}
REF: ${{ github.ref }}
run: |
set -euo pipefail
git init -q
git remote add origin "https://github.com/${REPOSITORY}.git"
git fetch --depth 1 origin "${REF}"
git checkout --detach FETCH_HEAD

- name: 安装 .NET 8 SDK
run: |
set -euo pipefail
curl -fsSL https://dot.net/v1/dotnet-install.sh -o "${RUNNER_TEMP}/dotnet-install.sh"
bash "${RUNNER_TEMP}/dotnet-install.sh" --channel 8.0 --install-dir "${RUNNER_TEMP}/dotnet"
echo "${RUNNER_TEMP}/dotnet" >> "${GITHUB_PATH}"
echo "DOTNET_ROOT=${RUNNER_TEMP}/dotnet" >> "${GITHUB_ENV}"
"${RUNNER_TEMP}/dotnet/dotnet" --list-sdks

- name: 恢复测试依赖
env:
SUITE: ${{ matrix.suite }}
run: dotnet restore "tests/SLDataAPI.${SUITE}.Tests/SLDataAPI.${SUITE}.Tests.csproj"

- name: 运行逻辑测试
env:
SUITE: ${{ matrix.suite }}
run: dotnet test "tests/SLDataAPI.${SUITE}.Tests/SLDataAPI.${SUITE}.Tests.csproj" --configuration Release --no-restore --logger "trx;LogFileName=${SUITE}.trx" --results-directory "TestResults/${SUITE}"

- name: 写入步骤摘要
if: ${{ !cancelled() }}
env:
SUITE: ${{ matrix.suite }}
run: |
set -euo pipefail
python3 - << 'PY'
import os
import xml.etree.ElementTree as ET
from pathlib import Path

suite = os.environ["SUITE"]
reports = sorted(Path("TestResults", suite).glob("*.trx"))
lines = [f"### {suite}", ""]
if not reports:
lines.append("这次没有生成 TRX。结果以测试步骤的控制台输出为准。")
else:
root = ET.parse(reports[0]).getroot()
counters = next((el for el in root.iter() if el.tag.endswith("Counters")), None)
if counters is None:
raise SystemExit(f"{reports[0]} has no Counters element")
passed = int(counters.attrib.get("passed", "0"))
failed = int(counters.attrib.get("failed", "0")) + int(counters.attrib.get("error", "0"))
skipped = int(counters.attrib.get("notExecuted", "0"))
total = int(counters.attrib.get("total", "0"))
lines.extend(
[
f"- Passed: {passed}",
f"- Failed: {failed}",
f"- Skipped: {skipped}",
f"- Total: {total}",
]
)
lines.extend(
[
"",
"可下载的 TRX 制品目前不可用。仓库只允许 DNTOF 拥有的 action;在所有者允许官方 artifact action 之前,结果只留在作业日志和本摘要中。",
]
)
with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as handle:
handle.write("\n".join(lines) + "\n")
PY
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ Content-Type: application/json

---

## 逻辑回归测试

`tests/` 下有四套独立的 net8.0 xUnit 项目:`SLDataAPI.Auth.Tests`、`SLDataAPI.Features.Tests`、`SLDataAPI.Update.Tests`、`SLDataAPI.WebDav.Tests`。它们直接编译对应的纯逻辑源文件,不引用主工程 `SLDataAPI.csproj`,因此不需要游戏程序集、LabAPI 或 Unity,也不会编译、签名或打包 `SLDataAPI.dll`。

这些测试只做逻辑回归:鉴权与路径沙箱、节日 / 端点入参、更新检查与强名称判定、WebDAV 上传规则。不能代替进服集成,也不能说明完整插件在 SCP:SL 里可用。官方插件的编译与发布仍在本机完成。

本机已安装 .NET 8 SDK 时:

```bash
dotnet test tests/SLDataAPI.Auth.Tests/SLDataAPI.Auth.Tests.csproj -c Release
dotnet test tests/SLDataAPI.Features.Tests/SLDataAPI.Features.Tests.csproj -c Release
dotnet test tests/SLDataAPI.Update.Tests/SLDataAPI.Update.Tests.csproj -c Release
dotnet test tests/SLDataAPI.WebDav.Tests/SLDataAPI.WebDav.Tests.csproj -c Release
```

推送、Pull Request 和手动 `workflow_dispatch` 会走 `.github/workflows/functional-tests.yml`:在 GitHub 托管的 `ubuntu-24.04` 上分别跑这四套。任一失败会使该检查失败,其余套件仍会跑完。控制台日志和作业摘要里有每套的通过 / 失败 / 跳过数量。

仓库的 Actions 策略只允许 DNTOF 拥有的 action,所以这条工作流用 git 检出、官方 `dotnet-install.sh` 安装 .NET 8,不调用其他组织的 action。可下载的 TRX 制品目前不可用,要等所有者允许官方的 artifact action 之后才能保留。

---

## 支持

- QQ 群:984840871
Expand Down