-
Notifications
You must be signed in to change notification settings - Fork 23
140 lines (125 loc) · 5.35 KB
/
Copy pathci.yml
File metadata and controls
140 lines (125 loc) · 5.35 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: CI
on:
workflow_dispatch:
push:
branches: [master2, master]
pull_request:
branches: [master2, master]
jobs:
test:
name: test (${{ matrix.arch }})
strategy:
fail-fast: false
matrix:
include:
- arch: x64
runner: windows-latest
python-architecture: x64
python-machine: amd64
rust-target: x86_64-pc-windows-msvc
- arch: arm64
runner: windows-11-arm
python-architecture: arm64
python-machine: arm64
rust-target: aarch64-pc-windows-msvc
runs-on: ${{ matrix.runner }}
env:
# PySide6 GUI 组件在无桌面会话的 CI Runner 上需要离屏渲染
QT_QPA_PLATFORM: offscreen
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# diff-cover 需要和目标分支做 diff,浅克隆里没有 base 分支的历史
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
architecture: ${{ matrix.python-architecture }}
cache: "pip"
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- name: Verify native toolchain architecture
run: |
python -c "import platform; actual = platform.machine().lower(); expected = '${{ matrix.python-machine }}'; assert actual == expected, f'Python architecture {actual!r} != {expected!r}'"
$hostLine = rustc -vV | Select-String '^host:'
if ($hostLine -notmatch '${{ matrix.rust-target }}') {
throw "Rust host does not match ${{ matrix.rust-target }}: $hostLine"
}
- name: Cache cargo registry and target
uses: Swatinem/rust-cache@v2
with:
workspaces: rust_libs
cache-on-failure: true
- name: Run Rust unit tests
run: cargo test --locked --workspace --release --target ${{ matrix.rust-target }} --manifest-path rust_libs/Cargo.toml
- name: Build and install Rust wheels from this commit
run: |
python -m pip install --upgrade pip
python -m pip install maturin==1.12.6
foreach ($crate in "gifrecorder", "longstitch", "pyclipboard", "ppocr_rust") {
maturin build --locked --release --target ${{ matrix.rust-target }} -i python -m rust_libs/$crate/Cargo.toml --out wheelhouse
if ($LASTEXITCODE -ne 0) { throw "$crate wheel build failed" }
}
python -m pip install (Get-ChildItem wheelhouse\*.whl).FullName
python -c "import gifrecorder, longstitch, pyclipboard, ppocr_rust; print('Native extension imports OK')"
- name: Install Python dependencies
run: |
python -m pip install -r requirements.txt
python -m pip install -r requirements-dev.txt
- name: Lint with ruff
if: matrix.arch == 'x64'
# 规则集见 pyproject.toml:只启用能指向真实缺陷的检查。
# 当前为零告警,新增违规会让 CI 变红。
run: ruff check main
- name: Run test suite with coverage
# 从仓库根目录运行,保证 .coveragerc 里的相对路径能正确解析。
# --cov-fail-under 是一个只升不降的棘轮:覆盖率掉下去 CI 就红,
# 补完测试后把这个数字往上调。
run: >
pytest main/tests -v
-c main/tests/pytest.ini
--cov --cov-config=.coveragerc
--cov-report=term:skip-covered
--cov-report=xml
--cov-fail-under=37
- name: Exercise the real ARM64 clipboard watcher
if: matrix.arch == 'arm64'
env:
RUN_CLIPBOARD_MONITOR_BENCHMARK: "1"
run: >
pytest main/tests/test_clipboard_monitoring_performance.py
-c main/tests/pytest.ini -v -s
- name: Enforce coverage on changed lines
# 只对本次 PR 改动到的行设门槛:总量棘轮(上一步的 --cov-fail-under)
# 防止倒退,这一步防止「新代码不带测试」。两者互补——总量涨得慢是因为
# 存量 UI 代码基数大,不能因此放过新写的未测代码。
# push 事件下 base 就是自己,diff 为空,因此只在 PR 上跑。
# if 用 always():即使总量棘轮把上一步判红,也要把增量报告给出来。
if: always() && matrix.arch == 'x64' && github.event_name == 'pull_request'
run: |
if (-not (Test-Path coverage.xml)) {
Write-Host "没有 coverage.xml(测试步骤未产出),跳过增量覆盖率检查"
exit 0
}
diff-cover coverage.xml `
--compare-branch=origin/${{ github.base_ref }} `
--fail-under=80 `
--format "html:diff-coverage.html,markdown:diff-coverage.md"
- name: Publish diff coverage summary
if: always() && matrix.arch == 'x64' && github.event_name == 'pull_request'
run: |
if (Test-Path diff-coverage.md) {
Get-Content diff-coverage.md | Add-Content -Path $env:GITHUB_STEP_SUMMARY
}
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-xml-${{ matrix.arch }}
path: |
coverage.xml
diff-coverage.html
if-no-files-found: warn