-
Notifications
You must be signed in to change notification settings - Fork 2
feat(ci): 增加覆盖率测试 #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,177 @@ | ||||||||||||||||||||||||||||||||||||||
| name: CI | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||
| # 仅在 push 时触发测试 | ||||||||||||||||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||
| test: | ||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||
| strategy: | ||||||||||||||||||||||||||||||||||||||
| matrix: | ||||||||||||||||||||||||||||||||||||||
| python-version: ['3.10'] | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||
| - name: Checkout code | ||||||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||
| fetch-depth: 0 # 获取完整历史用于增量覆盖率检查 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: Set up Python ${{ matrix.python-version }} | ||||||||||||||||||||||||||||||||||||||
| uses: actions/setup-python@v5 | ||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||
| python-version: ${{ matrix.python-version }} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - name: Install dependencies | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| make setup PYTHON_VERSION=${{ matrix.python-version }} | ||||||||||||||||||||||||||||||||||||||
| - name: Run type check (mypy) | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| make mypy-check | ||||||||||||||||||||||||||||||||||||||
| - name: Run unit tests | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| make test-unit | ||||||||||||||||||||||||||||||||||||||
| - name: Run coverage | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| make coverage | ||||||||||||||||||||||||||||||||||||||
| # 检测文件更改并决定是否构建测试包 | ||||||||||||||||||||||||||||||||||||||
| - name: Check for changes in agentrun directory | ||||||||||||||||||||||||||||||||||||||
| id: changes | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| echo "Checking if agentrun directory has changes..." | ||||||||||||||||||||||||||||||||||||||
| # 获取最近两次提交之间的差异;如果没有父提交,则将所有跟踪文件视为已更改 | ||||||||||||||||||||||||||||||||||||||
| if git rev-parse HEAD^ >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||||||||||
| git diff --name-only HEAD^ HEAD > changed_files.txt | ||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||
| echo "No parent commit; treating all tracked files as changed." | ||||||||||||||||||||||||||||||||||||||
| git ls-files > changed_files.txt | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| echo "Changed files:" | ||||||||||||||||||||||||||||||||||||||
| cat changed_files.txt || echo "No changed files detected" | ||||||||||||||||||||||||||||||||||||||
| # 检查是否有任何以 agentrun/ 开头的文件 | ||||||||||||||||||||||||||||||||||||||
| if grep -q "^agentrun/" changed_files.txt 2>/dev/null; then | ||||||||||||||||||||||||||||||||||||||
| echo "agentrun directory has changes" | ||||||||||||||||||||||||||||||||||||||
| echo "agentrun_changed=true" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||
| echo "agentrun directory has no changes" | ||||||||||||||||||||||||||||||||||||||
| echo "agentrun_changed=false" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| # 测试通过后自动构建测试包(仅在 agentrun 目录有变化时触发) | ||||||||||||||||||||||||||||||||||||||
| - name: Get latest version from PyPI and calculate next version | ||||||||||||||||||||||||||||||||||||||
| id: version | ||||||||||||||||||||||||||||||||||||||
| if: steps.changes.outputs.agentrun_changed == 'true' | ||||||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||||||
| # 从 PyPI 获取 agentrun-inner-test 的最新版本 | ||||||||||||||||||||||||||||||||||||||
| PYPI_RESPONSE=$(curl -s https://pypi.org/pypi/agentrun-inner-test/json 2>/dev/null || echo "") | ||||||||||||||||||||||||||||||||||||||
| if [ -z "$PYPI_RESPONSE" ] || echo "$PYPI_RESPONSE" | grep -q "Not Found"; then | ||||||||||||||||||||||||||||||||||||||
| # 如果包不存在,从 0.0.0 开始 | ||||||||||||||||||||||||||||||||||||||
| CURRENT_VERSION="0.0.0" | ||||||||||||||||||||||||||||||||||||||
| echo "Package not found on PyPI, starting from 0.0.0" | ||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||
| # 从 PyPI 响应中提取最新版本 | ||||||||||||||||||||||||||||||||||||||
| CURRENT_VERSION=$(echo "$PYPI_RESPONSE" | python3 -c "import sys, json; print(json.load(sys.stdin)['info']['version'])") | ||||||||||||||||||||||||||||||||||||||
| echo "Latest version on PyPI: $CURRENT_VERSION" | ||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||
| # 解析版本号 | ||||||||||||||||||||||||||||||||||||||
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | ||||||||||||||||||||||||||||||||||||||
| # 默认为 patch | ||||||||||||||||||||||||||||||||||||||
| BUMP_TYPE="patch" | ||||||||||||||||||||||||||||||||||||||
| case "$BUMP_TYPE" in | ||||||||||||||||||||||||||||||||||||||
| major) | ||||||||||||||||||||||||||||||||||||||
| MAJOR=$((MAJOR + 1)) | ||||||||||||||||||||||||||||||||||||||
| MINOR=0 | ||||||||||||||||||||||||||||||||||||||
| PATCH=0 | ||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||
| minor) | ||||||||||||||||||||||||||||||||||||||
| MINOR=$((MINOR + 1)) | ||||||||||||||||||||||||||||||||||||||
| PATCH=0 | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+81
to
+96
|
||||||||||||||||||||||||||||||||||||||
| fi | |
| # 解析版本号 | |
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | |
| # 默认为 patch | |
| BUMP_TYPE="patch" | |
| case "$BUMP_TYPE" in | |
| major) | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| ;; | |
| minor) | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| # 始终执行 patch 版本号递增 | |
| PATCH=$((PATCH + 1)) |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded constant: The BUMP_TYPE is always set to "patch" and the subsequent case statement is unnecessary. Consider removing the case statement entirely and just implementing the patch logic directly, or make BUMP_TYPE configurable if different bump types are needed in the future.
| # 默认为 patch | |
| BUMP_TYPE="patch" | |
| case "$BUMP_TYPE" in | |
| major) | |
| MAJOR=$((MAJOR + 1)) | |
| MINOR=0 | |
| PATCH=0 | |
| ;; | |
| minor) | |
| MINOR=$((MINOR + 1)) | |
| PATCH=0 | |
| ;; | |
| patch) | |
| PATCH=$((PATCH + 1)) | |
| ;; | |
| esac | |
| # 始终进行 patch 版本号递增 | |
| PATCH=$((PATCH + 1)) |
Copilot
AI
Dec 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The workflow automatically publishes packages to PyPI on every push where agentrun/ files change, without requiring manual approval or additional checks. This could lead to unintended package publications. Consider adding a condition to only publish on specific branches (e.g., main) or requiring manual approval for production releases.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,15 @@ on: | |||||
| - patch # 0.0.1 -> 0.0.2 | ||||||
| - minor # 0.0.1 -> 0.1.0 | ||||||
| - major # 0.0.1 -> 1.0.0 | ||||||
|
|
||||||
| # 支持被其他工作流调用(CI 测试通过后自动触发) | ||||||
| workflow_call: | ||||||
| inputs: | ||||||
| version_bump: | ||||||
| description: '版本递增类型' | ||||||
| required: false | ||||||
| default: 'patch' | ||||||
| type: string | ||||||
|
|
||||||
| jobs: | ||||||
| release-test: | ||||||
|
|
@@ -49,8 +58,8 @@ jobs: | |||||
| # 解析版本号 | ||||||
| IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | ||||||
|
|
||||||
| # 根据用户选择递增版本 | ||||||
| BUMP_TYPE="${{ inputs.version_bump }}" | ||||||
| # 根据用户选择递增版本(默认为 patch) | ||||||
|
||||||
| # 根据用户选择递增版本(默认为 patch) | |
| # 根据用户选择递增版本(默认值由 workflow inputs 定义,此处未提供时回退为 patch) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,4 +102,6 @@ dmypy.json | |
| .pytest_cache | ||
| .env | ||
|
|
||
| uv.lock | ||
| uv.lock | ||
| coverage.json | ||
| coverage.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # 覆盖率配置文件 | ||
| # Coverage Configuration File | ||
|
|
||
| # ============================================================================ | ||
| # 全量代码覆盖率要求 | ||
| # ============================================================================ | ||
| full: | ||
| # 分支覆盖率要求 (百分比) | ||
| branch_coverage: 0 | ||
| # 行覆盖率要求 (百分比) | ||
| line_coverage: 0 | ||
|
|
||
| # ============================================================================ | ||
| # 增量代码覆盖率要求 (相对于基准分支的变更代码) | ||
| # ============================================================================ | ||
| incremental: | ||
| # 分支覆盖率要求 (百分比) | ||
| branch_coverage: 0 | ||
| # 行覆盖率要求 (百分比) | ||
| line_coverage: 0 | ||
|
|
||
| # ============================================================================ | ||
| # 特定目录的覆盖率要求 | ||
| # 可以为特定目录设置不同的覆盖率阈值 | ||
| # ============================================================================ | ||
| directory_overrides: | ||
| # 为除 server 外的所有文件夹设置 0% 覆盖率要求 | ||
| # 这样可以逐个文件夹增加测试,暂时跳过未测试的文件夹 | ||
| agentrun/agent_runtime: | ||
| full: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
| incremental: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
|
|
||
| agentrun/credential: | ||
| full: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
| incremental: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
|
|
||
| agentrun/integration: | ||
| full: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
| incremental: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
|
|
||
| agentrun/model: | ||
| full: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
| incremental: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
|
|
||
| agentrun/sandbox: | ||
| full: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
| incremental: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
|
|
||
| agentrun/toolset: | ||
| full: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
| incremental: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
|
|
||
| agentrun/utils: | ||
| full: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
| incremental: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
|
|
||
| # server 模块保持默认的 95% 覆盖率要求 | ||
| agentrun/server: | ||
| full: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
| incremental: | ||
| branch_coverage: 0 | ||
| line_coverage: 0 | ||
|
Comment on lines
+85
to
+92
|
||
|
|
||
| # ============================================================================ | ||
| # 排除配置 | ||
| # ============================================================================ | ||
|
|
||
| # 排除的目录(不计入覆盖率统计) | ||
| exclude_directories: | ||
| - "tests/" | ||
| - "*__pycache__*" | ||
| - "*_async_template.py" | ||
| - "codegen/" | ||
| - "examples/" | ||
| - "build/" | ||
| - "*.egg-info" | ||
|
|
||
| # 排除的文件模式 | ||
| exclude_patterns: | ||
| - "*_test.py" | ||
| - "test_*.py" | ||
| - "conftest.py" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "仅在 push 时触发测试" (only triggered on push), but this will run on every push to any branch. Consider adding branch filters or documenting whether this is intentional, especially since the workflow includes automated package publishing which might not be desired for all branches.