-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (134 loc) · 4.65 KB
/
python.yml
File metadata and controls
144 lines (134 loc) · 4.65 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
141
142
143
144
# Build the Python bindings (bindings/python) into wheels + sdist and,
# on a `v*` tag, publish to PyPI via trusted publishing (OIDC) - PyPI
# trusts this repo/workflow, so no token is stored on GitHub. The same
# tag also publishes the Rust crates (see crates.yml), since the crate
# and the PyPI package share one version. Wheels are abi3-py39, so one
# wheel per platform covers all CPython >= 3.9. A tag only publishes
# after the version-sync + smoke jobs pass.
#
# Wheels carry GPU rows: macOS builds with `--features mac` (sudo-free
# IOKit/IOReport), Linux with `--features cuda` (NVML, loaded from the
# driver at run time). NVML init degrades gracefully when no NVIDIA
# driver is present, so the Linux wheel is safe on CPU-only boxes - the
# gpu_* rows just read zero there.
name: python
on:
push:
tags: ["v*"]
pull_request:
paths:
- "bindings/python/**"
- "src/**"
- ".github/workflows/python.yml"
workflow_dispatch:
permissions:
contents: read
jobs:
wheels:
name: wheels (${{ matrix.platform.target }})
runs-on: ${{ matrix.platform.runner }}
strategy:
fail-fast: false
matrix:
platform:
- { runner: macos-14, target: aarch64-apple-darwin, args: "--features mac" }
- { runner: ubuntu-latest, target: x86_64, args: "--features cuda" }
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
working-directory: bindings/python
# vor's MSRV is 1.96; the action's pinned default lags it.
rust-toolchain: stable
target: ${{ matrix.platform.target }}
manylinux: auto
args: --release --out dist ${{ matrix.platform.args }}
- uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.platform.target }}
path: bindings/python/dist
sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: PyO3/maturin-action@v1
with:
working-directory: bindings/python
rust-toolchain: stable
command: sdist
args: --out dist
- uses: actions/upload-artifact@v4
with:
name: sdist
path: bindings/python/dist
versions:
name: versions in sync
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# The Rust crate and the PyPI package share one version; a release
# tag must not ship a drifted pair.
- run: |
rust=$(grep -m1 '^version = ' Cargo.toml | cut -d'"' -f2)
py=$(grep -m1 '^version = ' bindings/python/Cargo.toml | cut -d'"' -f2)
echo "rust=$rust pypi=$py"
test "$rust" = "$py"
smoke:
name: smoke (capture from Python, read back in Rust)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable # for the cargo-run read-back (MSRV 1.96)
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: PyO3/maturin-action@v1
with:
working-directory: bindings/python
rust-toolchain: stable
command: build
manylinux: auto
args: --release --out dist --features cuda
- name: install the wheel
run: pip install bindings/python/dist/*.whl
- name: capture a run from Python
env:
VOR_RECORD: /tmp/smoke.vor
run: |
python - <<'PY'
import vor
vor.record_metric_unit("loss", "")
vor.enable() # no NVIDIA driver here: NVML degrades, no crash
@vor.profile
def step(i):
return i * 2
for i in range(64):
step(i)
vor.record_metric("loss", 1.0 / (i + 1))
vor.frame_mark()
vor.flush()
print("captured 64 frames")
PY
- name: read the capture back with the Rust reader
run: |
cargo run --quiet --example headless -- /tmp/smoke.vor | tee out.txt
grep -Eq "frames: [1-9][0-9]*" out.txt
publish:
name: publish to PyPI
if: startsWith(github.ref, 'refs/tags/v')
needs: [versions, smoke, wheels, sdist]
runs-on: ubuntu-latest
# One-time PyPI setup (project settings -> Publishing): add a trusted
# publisher for owner SConsul, repo vor, workflow python.yml,
# environment pypi. No secret is stored on GitHub.
environment: pypi
permissions:
id-token: write # OIDC token minted per run; PyPI verifies it
steps:
- uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist