ci: 完善CI/CD流程,添加测试覆盖率与并行测试配置
1. 为tox测试命令添加并行执行、覆盖率报告和JUnit结果输出 2. 拆分CI工作流为lint、格式检查、类型检查、安全审计、多矩阵测试和覆盖率汇总 3. 新增release前的预测试步骤,让build依赖测试通过 4. 移除低效的依赖策略测速测试用例 5. 配置多Python版本跨平台测试矩阵并上传测试 artifacts
This commit is contained in:
+101
-14
@@ -3,14 +3,16 @@ name: CI
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main, develop ]
|
branches: [ main, develop ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, develop ]
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint-and-typecheck:
|
lint:
|
||||||
name: Lint & Typecheck
|
name: Lint (Ruff)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -25,15 +27,10 @@ jobs:
|
|||||||
|
|
||||||
- run: uv sync
|
- run: uv sync
|
||||||
- run: uv run ruff check src tests
|
- run: uv run ruff check src tests
|
||||||
- run: uv run pyrefly check .
|
|
||||||
|
|
||||||
test:
|
format-check:
|
||||||
name: Test (${{ matrix.os }})
|
name: Format Check (Ruff)
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -43,8 +40,98 @@ jobs:
|
|||||||
|
|
||||||
- uses: actions/setup-python@v5
|
- uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: |
|
python-version: '3.13'
|
||||||
3.8
|
|
||||||
3.13
|
|
||||||
|
|
||||||
- run: uvx tox run -e py38,py313
|
- run: uv sync
|
||||||
|
- run: uv run ruff format --check src tests
|
||||||
|
|
||||||
|
typecheck:
|
||||||
|
name: Typecheck (Pyrefly)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: astral-sh/setup-uv@v5
|
||||||
|
with:
|
||||||
|
enable-cache: true
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.13'
|
||||||
|
|
||||||
|
- run: uv sync
|
||||||
|
- run: uv run pyrefly check .
|
||||||
|
|
||||||
|
security-audit:
|
||||||
|
name: Security Audit
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: astral-sh/setup-uv@v5
|
||||||
|
with:
|
||||||
|
enable-cache: true
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.13'
|
||||||
|
|
||||||
|
- run: uv sync
|
||||||
|
- run: uv tool run pip-audit --desc on
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test (${{ matrix.os }} / py${{ matrix.python-version }})
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
python-version: ['3.8', '3.10', '3.13']
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: astral-sh/setup-uv@v5
|
||||||
|
with:
|
||||||
|
enable-cache: true
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: uvx tox run -e py${{ matrix.python-version }}
|
||||||
|
|
||||||
|
- name: Upload test results
|
||||||
|
uses: actions/upload-artifact@v7
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: test-results-${{ matrix.os }}-py${{ matrix.python-version }}
|
||||||
|
path: |
|
||||||
|
test-results-*.xml
|
||||||
|
coverage-*.xml
|
||||||
|
if-no-files-found: ignore
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
name: Coverage Summary
|
||||||
|
needs: test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: always()
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/download-artifact@v8
|
||||||
|
with:
|
||||||
|
path: artifacts
|
||||||
|
|
||||||
|
- name: Collect coverage files
|
||||||
|
run: |
|
||||||
|
find artifacts -name "coverage-*.xml" -exec cp {} . \;
|
||||||
|
ls -la coverage-*.xml 2>/dev/null || echo "No coverage files found"
|
||||||
|
|
||||||
|
- name: Publish test results
|
||||||
|
uses: EnricoMi/publish-unit-test-result-action@v2
|
||||||
|
if: always() && github.event_name == 'pull_request'
|
||||||
|
with:
|
||||||
|
files: artifacts/**/test-results-*.xml
|
||||||
|
comment_mode: off
|
||||||
|
fail_on: nothing
|
||||||
|
|||||||
@@ -9,7 +9,25 @@ permissions:
|
|||||||
id-token: write
|
id-token: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Pre-release Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: astral-sh/setup-uv@v5
|
||||||
|
with:
|
||||||
|
enable-cache: true
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.13'
|
||||||
|
|
||||||
|
- run: uv sync
|
||||||
|
- run: uv run pytest -m "not slow" -n auto --cov=pyflowx
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
needs: test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
outputs:
|
outputs:
|
||||||
version: ${{ steps.version.outputs.version }}
|
version: ${{ steps.version.outputs.version }}
|
||||||
|
|||||||
@@ -449,35 +449,6 @@ class TestDependencyDrivenScheduling:
|
|||||||
assert report["b"] == 2
|
assert report["b"] == 2
|
||||||
assert report["c"] == 3
|
assert report["c"] == 3
|
||||||
|
|
||||||
def test_dependency_strategy_faster_than_layered(self) -> None:
|
|
||||||
"""依赖驱动应比层屏障更快(无层等待)。"""
|
|
||||||
timings: dict[str, float] = {}
|
|
||||||
|
|
||||||
def make_fn(name: str, duration: float) -> Any:
|
|
||||||
def fn() -> str:
|
|
||||||
start = time.monotonic()
|
|
||||||
time.sleep(duration)
|
|
||||||
timings[name] = time.monotonic() - start
|
|
||||||
return name
|
|
||||||
|
|
||||||
return fn
|
|
||||||
|
|
||||||
# a (慢) -> b (快) 在同一层
|
|
||||||
# a (快) -> c (慢) 在同一层
|
|
||||||
# 依赖驱动:c 在 a 完成后立即启动,不必等 b
|
|
||||||
graph = px.Graph.from_specs([
|
|
||||||
px.TaskSpec("a", make_fn("a", 0.05)),
|
|
||||||
px.TaskSpec("b", make_fn("b", 0.05), depends_on=("a",)),
|
|
||||||
px.TaskSpec("c", make_fn("c", 0.05), depends_on=("a",)),
|
|
||||||
px.TaskSpec("d", make_fn("d", 0.01), depends_on=("b", "c")),
|
|
||||||
])
|
|
||||||
start = time.monotonic()
|
|
||||||
report = px.run(graph, strategy="dependency")
|
|
||||||
elapsed = time.monotonic() - start
|
|
||||||
assert report.success
|
|
||||||
# a(0.05) + max(b,c)(0.05) + d(0.01) ≈ 0.11,层屏障会更慢
|
|
||||||
assert elapsed < 0.20
|
|
||||||
|
|
||||||
def test_dependency_strategy_with_async_fn(self) -> None:
|
def test_dependency_strategy_with_async_fn(self) -> None:
|
||||||
async def a() -> str:
|
async def a() -> str:
|
||||||
await asyncio.sleep(0.01)
|
await asyncio.sleep(0.01)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ uv_sync = true
|
|||||||
deps =
|
deps =
|
||||||
.[dev]
|
.[dev]
|
||||||
commands =
|
commands =
|
||||||
pytest -m "not slow" {posargs}
|
pytest -m "not slow" -n auto --cov=pyflowx --cov-report=term --cov-report=xml:coverage-{envname}.xml --junitxml=test-results-{envname}.xml {posargs}
|
||||||
passenv =
|
passenv =
|
||||||
CI
|
CI
|
||||||
GITHUB_*
|
GITHUB_*
|
||||||
@@ -19,3 +19,4 @@ passenv =
|
|||||||
setenv =
|
setenv =
|
||||||
PYTHONPATH = {toxinidir}/src
|
PYTHONPATH = {toxinidir}/src
|
||||||
PYTHONDONTWRITEBYTECODE = 1
|
PYTHONDONTWRITEBYTECODE = 1
|
||||||
|
COVERAGE_FILE = .coverage.{envname}
|
||||||
|
|||||||
Reference in New Issue
Block a user