Repository navigation
82 lines (74 loc) · 2.84 KB
/
Copy pathtest-python-pr.yml
File metadata and controls
82 lines (74 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Test When Python PR
on:
pull_request:
# Run automatically for non-draft PRs and when a draft PR becomes ready for review.
types: [opened, synchronize, reopened, ready_for_review]
paths:
- "swanlab/**"
- "tests/**"
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/test-python-pr.yml"
workflow_dispatch:
concurrency:
# Share concurrency group between PR runs and manual runs on the same repo/branch,
# while keeping fork PRs with identical branch names isolated.
group: ${{ github.workflow }}-${{ github.event.pull_request.head.repo.full_name || github.repository }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
jobs:
type-check:
name: Type check / Python 3.9
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Install uv and set up Python
uses: astral-sh/setup-uv@v10.0.0
with:
python-version: "3.9"
enable-cache: true
- name: Install dependencies
run: uv sync --all-extras --group dev
- name: Run ruff
run: uv run ruff check .
- name: Run basedpyright
run: uv run basedpyright
test:
needs: type-check
name: Test on ${{ matrix.os }} / Python ${{ matrix.python-version }}
if: ${{ !github.event.pull_request.draft }}
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false # 设为 false,这样如果 Windows 挂了,Ubuntu 的测试依然会跑完,方便一次性排查所有系统的问题
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Install uv and set up Python
uses: astral-sh/setup-uv@v10.0.0
with:
python-version: ${{ matrix.python-version }}
# 开启缓存,进一步加速后续的 CI 运行
enable-cache: true
- name: Install dependencies
run: uv sync --all-extras
- name: Run tests with pytest
# uv run 会自动识别当前的虚拟环境并执行 pytest
run: uv run pytest
check:
# 聚合所有前置 job 的结果,供 GitHub ruleset 配置单一 required status check
name: Check
needs: [type-check, test]
# 非 Draft 时始终运行,确保前置失败或取消时汇报 failure 而不是被 skip
if: ${{ !github.event.pull_request.draft && always() }}
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Fail if any required job failed or was cancelled
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}
run: exit 1