|
1 | 1 | # ============================================================================= |
2 | | -# CI Workflow - PR 检查 |
3 | | -# 触发条件: Pull Request 和 push 到 main 分支 |
4 | | -# 测试策略: |
5 | | -# - PR/push: 仅测试 Python 3.8 (最小版本,快速反馈) |
6 | | -# - main 分支: 全矩阵测试 Python 3.8-3.12 (完整回归测试) |
7 | | -# 功能: |
8 | | -# 1. 代码格式检查 (ruff) |
9 | | -# 2. 类型检查 (mypy) |
10 | | -# 3. 运行测试 (pytest + tox) |
11 | | -# 安全模型: 本工作流不需要写权限,可安全运行 fork PR 代码 |
| 2 | +# CI Workflow - PR Check |
| 3 | +# Trigger: Pull Request and push to main branch |
| 4 | +# Testing strategy: |
| 5 | +# - PR/push: Test only Python 3.8 (minimum version, fast feedback) |
| 6 | +# - main branch: Full matrix test Python 3.8-3.12 (complete regression) |
| 7 | +# Features: |
| 8 | +# 1. Code format check (ruff) |
| 9 | +# 2. Type check (mypy) |
| 10 | +# 3. Language check (no Chinese in source code) |
| 11 | +# 4. Run tests (pytest + tox) |
| 12 | +# Security: This workflow doesn't need write permission, safe for fork PRs |
12 | 13 | # ============================================================================= |
13 | 14 |
|
14 | 15 | name: CI |
|
19 | 20 | push: |
20 | 21 | branches: [main] |
21 | 22 |
|
22 | | -# 自动取消同一分支的旧任务 |
| 23 | +# Auto-cancel old tasks on same branch |
23 | 24 | concurrency: |
24 | 25 | group: ${{ github.workflow }}-${{ github.ref }} |
25 | 26 | cancel-in-progress: true |
26 | 27 |
|
27 | 28 | permissions: |
28 | | - contents: read # 只需要读权限 |
| 29 | + contents: read # Read permission only |
29 | 30 |
|
30 | 31 | jobs: |
31 | 32 | # =========================================================================== |
32 | | - # 代码质量检查 |
| 33 | + # Code Quality Check |
33 | 34 | # =========================================================================== |
34 | 35 | lint: |
35 | 36 | name: Lint & Format Check |
|
65 | 66 | run: ruff check src/ tests/ |
66 | 67 |
|
67 | 68 | # =========================================================================== |
68 | | - # 类型检查 |
| 69 | + # Language Check - No Chinese in source code |
| 70 | + # =========================================================================== |
| 71 | + language-check: |
| 72 | + name: Language Check |
| 73 | + runs-on: ubuntu-latest |
| 74 | + |
| 75 | + steps: |
| 76 | + - name: Checkout code |
| 77 | + uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Set up Python |
| 80 | + uses: actions/setup-python@v5 |
| 81 | + with: |
| 82 | + python-version: "3.8" |
| 83 | + |
| 84 | + - name: Run language check |
| 85 | + run: python scripts/check_language.py |
| 86 | + |
| 87 | + # =========================================================================== |
| 88 | + # Type Check |
69 | 89 | # =========================================================================== |
70 | 90 | type-check: |
71 | 91 | name: Type Check |
@@ -98,24 +118,24 @@ jobs: |
98 | 118 | run: mypy src/ |
99 | 119 |
|
100 | 120 | # =========================================================================== |
101 | | - # 测试 - 差异化策略 |
102 | | - # PR: 仅测试 Python 3.8 (快速反馈) |
103 | | - # main 分支: 全矩阵测试 Python 3.8-3.12 (完整回归) |
| 121 | + # Test - Differentiated Strategy |
| 122 | + # PR: Test only Python 3.8 (fast feedback) |
| 123 | + # main branch: Full matrix test Python 3.8-3.12 (complete regression) |
104 | 124 | # =========================================================================== |
105 | 125 | test: |
106 | 126 | name: Test (Python ${{ matrix.python-version }}) |
107 | 127 | runs-on: ubuntu-latest |
108 | 128 | strategy: |
109 | 129 | fail-fast: false |
110 | 130 | matrix: |
111 | | - # PR 只测试最小版本,main 分支测试全矩阵 |
| 131 | + # PR tests minimum version only, main branch tests full matrix |
112 | 132 | python-version: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && fromJSON('["3.8", "3.9", "3.10", "3.11", "3.12"]') || fromJSON('["3.8"]') }} |
113 | 133 |
|
114 | 134 | steps: |
115 | 135 | - name: Checkout code |
116 | 136 | uses: actions/checkout@v4 |
117 | 137 | with: |
118 | | - fetch-depth: 0 # setuptools-scm 需要 git 历史 |
| 138 | + fetch-depth: 0 # setuptools-scm needs git history |
119 | 139 |
|
120 | 140 | - name: Set up Python ${{ matrix.python-version }} |
121 | 141 | uses: actions/setup-python@v5 |
@@ -148,28 +168,28 @@ jobs: |
148 | 168 | path: pytest-report.xml |
149 | 169 | retention-days: 1 |
150 | 170 |
|
151 | | - # 只在 Python 3.12 上上传覆盖率报告 |
| 171 | + # Upload coverage report for all Python versions |
152 | 172 | - name: Upload coverage report |
153 | 173 | uses: actions/upload-artifact@v4 |
154 | | - if: always() && matrix.python-version == '3.12' |
| 174 | + if: always() |
155 | 175 | with: |
156 | 176 | name: coverage-${{ matrix.python-version }}-${{ github.run_id }} |
157 | 177 | path: coverage.xml |
158 | 178 | retention-days: 1 |
159 | 179 |
|
160 | 180 | # =========================================================================== |
161 | | - # 构建检查 |
| 181 | + # Build Check |
162 | 182 | # =========================================================================== |
163 | 183 | build: |
164 | 184 | name: Build Check |
165 | 185 | runs-on: ubuntu-latest |
166 | | - needs: [lint, type-check, test] |
| 186 | + needs: [lint, language-check, type-check, test] |
167 | 187 |
|
168 | 188 | steps: |
169 | 189 | - name: Checkout code |
170 | 190 | uses: actions/checkout@v4 |
171 | 191 | with: |
172 | | - fetch-depth: 0 # setuptools-scm 需要完整的 git 历史 |
| 192 | + fetch-depth: 0 # setuptools-scm needs full git history |
173 | 193 |
|
174 | 194 | - name: Set up Python |
175 | 195 | uses: actions/setup-python@v5 |
|
0 commit comments