Skip to content

Commit 069f76e

Browse files
committed
chore: update test configuration and environment variable handling in RAGFlowSharp
1 parent 6aecac8 commit 069f76e

8 files changed

Lines changed: 87 additions & 8 deletions

File tree

.github/RELEASE.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
## 配置要求
66

7-
### 1. 设置 NuGet API Key
7+
### 1. 设置必需的 Secrets
88

99
在 GitHub 仓库的 Settings → Secrets and variables → Actions 中添加以下秘钥:
1010

1111
- `NUGET_API_KEY`: 您的 NuGet.org API 密钥
12+
- `RAGFLOW_API_KEY`: 您的 RAGFlow API 密钥(用于运行测试)
13+
- `RAGFLOW_BASE_URL`: RAGFlow 服务的基础 URL(例如:http://localhost:8000)
1214

1315
### 2. 获取 NuGet API Key
1416

@@ -50,9 +52,43 @@
5052
- `.github/workflows/release.yml`: 在创建 Release 时触发,自动发布 NuGet 包
5153
- `.github/workflows/build-and-test.yml`: 在推送到 main 分支或创建 PR 时触发,进行构建和测试
5254

55+
## 测试配置
56+
57+
### 本地开发
58+
59+
如果您想在本地运行测试,需要设置以下环境变量:
60+
61+
```bash
62+
# Windows (PowerShell)
63+
$env:RAGFLOW_API_KEY="your-ragflow-api-key"
64+
$env:RAGFLOW_BASE_URL="http://localhost:8000"
65+
66+
# Linux/macOS
67+
export RAGFLOW_API_KEY="your-ragflow-api-key"
68+
export RAGFLOW_BASE_URL="http://localhost:8000"
69+
```
70+
71+
或者在 `RAGFlowSharp.Test/appsettings.json` 中直接配置:
72+
73+
```json
74+
{
75+
"RAGFlowSharp": {
76+
"BaseUrl": "http://localhost:8000",
77+
"ApiKey": "your-ragflow-api-key"
78+
}
79+
}
80+
```
81+
82+
**注意:** 为了安全起见,请不要将真实的 API 密钥提交到代码仓库中。
83+
84+
### CI/CD 测试
85+
86+
GitHub Actions 会自动从 Repository Secrets 中读取环境变量来运行测试。
87+
5388
## 注意事项
5489

5590
- 确保标签版本号符合语义化版本规范
5691
- 发布前请确保所有测试通过
5792
- NuGet 包名会根据项目名称自动生成
58-
- 如果版本号已存在,发布会被跳过(使用 --skip-duplicate 参数)
93+
- 如果版本号已存在,发布会被跳过(使用 --skip-duplicate 参数)
94+
- 测试需要有效的 RAGFlow API 密钥和服务 URL

.github/workflows/build-and-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ jobs:
2525
run: dotnet build --configuration Release --no-restore
2626

2727
- name: Test
28-
run: dotnet test --no-build --verbosity normal --configuration Release
28+
run: dotnet test --no-build --verbosity normal --configuration Release
29+
env:
30+
RAGFLOW_API_KEY: ${{ secrets.RAGFLOW_API_KEY }}
31+
RAGFLOW_BASE_URL: ${{ secrets.RAGFLOW_BASE_URL }}

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424

2525
- name: Test
2626
run: dotnet test --no-build --verbosity normal --configuration Release
27+
env:
28+
RAGFLOW_API_KEY: ${{ secrets.RAGFLOW_API_KEY }}
29+
RAGFLOW_BASE_URL: ${{ secrets.RAGFLOW_BASE_URL }}
2730

2831
- name: Extract version from tag
2932
id: get_version

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,6 @@ $RECYCLE.BIN/
482482

483483
# Vim temporary swap files
484484
*.swp
485+
486+
# test configuration file
487+
RAGFlowSharp.Test/appsettings.json

RAGFlowSharp.Test/RAGFlowSharp.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<ItemGroup>
1111
<PackageReference Include="coverlet.collector" Version="6.0.2"/>
1212
<PackageReference Include="JetBrains.Annotations" Version="2025.1.0-eap1" />
13+
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.3.0"/>
14+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0"/>
15+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0"/>
1316
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
1417
<PackageReference Include="xunit" Version="2.9.2"/>
1518
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"/>

RAGFlowSharp.Test/Startup.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.Extensions.Configuration;
13
using Microsoft.Extensions.DependencyInjection;
24
using Microsoft.Extensions.Logging;
35
using Xunit.DependencyInjection.Logging;
@@ -8,19 +10,35 @@ class Startup
810
{
911
public void ConfigureServices(IServiceCollection services)
1012
{
13+
// 构建配置
14+
var configuration = new ConfigurationBuilder()
15+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
16+
.AddEnvironmentVariables()
17+
.Build();
18+
19+
services.AddSingleton<IConfiguration>(configuration);
20+
21+
// 添加测试用的 HttpContextAccessor
22+
services.AddSingleton<IHttpContextAccessor, TestHttpContextAccessor>();
23+
1124
services.AddRagflowSharp(options =>
1225
{
13-
// options.ApiKey = "ragflow-U3MTFkNGFjMmMyNjExZjA5NjUxMDI0Mm";
14-
// options.BaseUrl = "http://localhost";
26+
// 从环境变量或配置文件中读取设置
27+
options.ApiKey = Environment.GetEnvironmentVariable("RAGFLOW_API_KEY")
28+
?? configuration["RAGFlowSharp:ApiKey"]
29+
?? throw new InvalidOperationException("RAGFLOW_API_KEY environment variable or RAGFlowSharp:ApiKey configuration is required");
30+
31+
options.BaseUrl = Environment.GetEnvironmentVariable("RAGFLOW_BASE_URL")
32+
?? configuration["RAGFlowSharp:BaseUrl"]
33+
?? "http://localhost:8000";
1534

16-
options.ApiKey = "ragflow-U3MTFkNGFjMmMyNjExZjA5NjUxMDI0Mm";
17-
options.BaseUrl = "http://localhost";
1835
options.EnableLogging = true;
1936
});
2037

2138
services.AddLogging(lb =>
2239
{
2340
lb.AddXunitOutput();
2441
});
42+
2543
}
2644
}

RAGFlowSharp.Test/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"RAGFlowSharp": {
33
"BaseUrl": "http://localhost:8000",
4-
"ApiKey": "your-api-key-here"
4+
"ApiKey": ""
55
},
66
"Logging": {
77
"LogLevel": {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"RAGFlowSharp": {
3+
"BaseUrl": "http://localhost:8000",
4+
"ApiKey": "<your-api-key>"
5+
},
6+
"Logging": {
7+
"LogLevel": {
8+
"Default": "Information",
9+
"Microsoft": "Warning",
10+
"Microsoft.Hosting.Lifetime": "Information"
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)