Files
gaokao-volunteer-system/.github/workflows/ci.yml
Hermes 361dbe5fbd
Some checks failed
CI / pytest (Python 3.10) (push) Has been cancelled
CI / pytest (Python 3.11) (push) Has been cancelled
CI / pytest (Python 3.12) (push) Has been cancelled
feat(ci): T10.2 codecov 集成 + 覆盖率徽章配置
完成 v2.1 实施计划 T10.2: codecov 集成与覆盖率徽章。

变更:
- .github/workflows/ci.yml: 新增 'Upload coverage to Codecov' 步骤
  - codecov/codecov-action@v4 (锁 major)
  - 3.11 单点上传,flag=python-3.11(避免矩阵多份报告冲突)
  - fail_ci_if_error: false(codecov 不可达不阻断 CI)
  - 不设 token: public repo 匿名上传即可
- codecov.yml: 配置文件
  - project target 60% / threshold 1% (与 T5.5 整体门槛对齐)
  - core (skills/gaokao-spec-checker + gaokao-college-advisor) target 80% / threshold 2%
  - patch target 70% / threshold 5%
  - ignore docs/tests/rules/scripts/gaokao-shortlink (非生产代码)
  - require_ci_to_pass: false (CI 失败不阻塞 codecov 上传)

本地验证:
- pytest 136/136 通过 (T7 修复后 test_route_short_link 已恢复)
- 整体覆盖率 59.55% (line-rate=0.5955, 2126/1266 lines)
- coverage.xml 是合法 Cobertura XML (codecov-action 可消费)
- ci.yml/codecov.yml YAML schema 解析通过

未在本任务范围: T5.5 --cov-fail-under 硬门槛启用、scripts/* 0% 覆盖率补齐、
core 模块 (gaokao-spec-checker 72%, 距 80% 差 8%) 补齐。
2026-06-12 11:02:11 +08:00

105 lines
3.3 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.
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
# 取消同一分支/同一次 push 的旧运行,避免资源浪费
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
test:
name: pytest (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: pip-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('requirements-dev.txt') }}
restore-keys: |
pip-${{ runner.os }}-py${{ matrix.python-version }}-
pip-${{ runner.os }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# 离线兜底:若 requirements-dev.txt 缺失CI 仍可运行(无第三方包)
if [ -f requirements-dev.txt ]; then
pip install -r requirements-dev.txt
else
echo "::warning::requirements-dev.txt not found, installing test deps directly"
pip install pytest pytest-cov
fi
- name: Verify Python and pytest versions
run: |
python --version
pytest --version
- name: Run tests with coverage
# 覆盖率硬门槛(--cov-fail-under由 T5.5 任务负责
# 本任务T10.1)只生成 coverage.xml 供 T10.2 codecov 集成使用
run: |
pytest \
--cov=data \
--cov=skills \
--cov=scripts \
--cov-report=term-missing \
--cov-report=xml \
-v
- name: Upload coverage artifact
if: matrix.python-version == '3.11'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
retention-days: 7
# T10.2: 上传 coverage.xml 到 codecov 渲染覆盖率徽章
# 关键决策:
# - 仅在 3.11 单点上传避免多份报告名冲突codecov 按文件名合并)
# - fail_ci_if_error: false: codecov 不可达时不影响 CI 通过(与个人项目 + 多镜像
# 仓库场景匹配tksea/gitea 不被 codecov 官方支持,无 token 时仍能上传但不写 status
# - 不设 token: public repo 可匿名上传;徽章正常渲染
- name: Upload coverage to Codecov
if: matrix.python-version == '3.11' && hashFiles('coverage.xml') != ''
uses: codecov/codecov-action@v4
with:
file: coverage.xml
flags: python-3.11
fail_ci_if_error: false
verbose: false
- name: Test summary
if: always()
run: |
echo "### CI Summary" >> $GITHUB_STEP_SUMMARY
echo "- Python: ${{ matrix.python-version }}" >> $GITHUB_STEP_SUMMARY
echo "- Status: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY
if [ -f coverage.xml ]; then
echo "- Coverage report: uploaded as artifact" >> $GITHUB_STEP_SUMMARY
fi