Skip to content

Commit a47348e

Browse files
authored
ci: reduce CI utilization in PRs (#102)
Adds a separate ci-pr.yml workflow which runs on PRs, while the full build-test.yml is now only run on commits to main, on tags and on workflow-dispatch. Shared behavior is consolidated into composite actions.
1 parent 6d77b1c commit a47348e

13 files changed

Lines changed: 260 additions & 126 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build wheel
2+
description: Build wheel with maturin
3+
inputs:
4+
target:
5+
required: true
6+
args:
7+
required: true
8+
manylinux:
9+
required: false
10+
before-script-linux:
11+
required: false
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Build wheel
16+
uses: PyO3/maturin-action@v1
17+
with:
18+
maturin-version: 1.9.6
19+
target: ${{ inputs.target }}
20+
args: ${{ inputs.args }}
21+
manylinux: ${{ inputs.manylinux }}
22+
before-script-linux: ${{ inputs.before-script-linux }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Cache Rust build
2+
description: Caches Rust build artifacts and dependencies
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Cache Rust build
7+
uses: actions/cache@v4
8+
with:
9+
path: |
10+
target
11+
~/.cargo/registry
12+
~/.cargo/git
13+
key: ${{ runner.os }}-test-${{ runner.arch }}-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
14+
restore-keys: |
15+
${{ runner.os }}-test-${{ runner.arch }}-
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Download wheels
2+
description: Download wheels artifact
3+
inputs:
4+
name:
5+
required: true
6+
path:
7+
required: true
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Download wheel
12+
uses: actions/download-artifact@v4
13+
with:
14+
name: ${{ inputs.name }}
15+
path: ${{ inputs.path }}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Install Python dependencies
2+
description: Install required Python dependencies using uv
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Install required python dependencies
7+
run: uv sync --no-install-project
8+
shell: bash
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Install uv
2+
description: Setup uv with caching
3+
inputs:
4+
python-version:
5+
description: Python version to use
6+
required: false
7+
default: ""
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Install uv
12+
uses: astral-sh/setup-uv@v7
13+
with:
14+
version: "0.9.11"
15+
enable-cache: true
16+
cache-dependency-glob: "**/uv.lock"
17+
python-version: ${{ inputs.python-version }}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Run cargo tests
2+
description: Run cargo tests with uv and proper environment
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Run cargo tests
7+
shell: bash
8+
run: |
9+
# pyo3 and uv do not work well together...
10+
PY_LIBDIR=$(uv run --no-sync python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
11+
echo "Python libdir: $PY_LIBDIR"
12+
# setting LD_LIBRARY_PATH for Linux: https://github.com/astral-sh/uv/issues/11006#issuecomment-2672486381
13+
export LD_LIBRARY_PATH="$PY_LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" # LINUX
14+
if [[ "$RUNNER_OS" == "Windows" ]]; then
15+
uv run --no-sync python -c "import sys; print(sys.path)"
16+
uv run --no-sync where python
17+
export PYTHONPATH="$(echo .venv/Lib/site-packages)"
18+
else
19+
# setting PYTHONHOME and PYTHONPATH seem to be the best solution for macOS at the moment
20+
# https://github.com/PyO3/pyo3/issues/1741#issuecomment-955805634
21+
export PYTHONHOME="$(uv run --no-sync python -c 'import sys; print(sys.base_prefix)')" # MACOS
22+
export PYTHONPATH="$(echo .venv/lib/python*/site-packages)" # MACOS
23+
fi
24+
uv run --no-sync cargo test --no-default-features
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Run Python tests
2+
description: Run Python tests with uv
3+
inputs:
4+
min-deps:
5+
required: false
6+
default: "false"
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Run tests
11+
shell: bash
12+
run: |
13+
WHEEL_PATH=$(ls dist/*.whl)
14+
uv venv
15+
if [[ "${{ inputs.min-deps }}" == "true" ]]; then
16+
uv sync --resolution lowest-direct --no-install-project --no-default-groups --group=test
17+
uv pip install --no-deps --force-reinstall "$WHEEL_PATH"
18+
uv run --no-sync --no-default-groups --group=test pytest tests/
19+
else
20+
uv sync --no-install-project --no-default-groups --group=test
21+
uv pip install --force-reinstall "$WHEEL_PATH"
22+
uv run --no-sync pytest tests/
23+
fi
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Test wheel
2+
description: Download and test a built wheel
3+
inputs:
4+
artifact-name:
5+
description: Name of the artifact to download
6+
required: true
7+
python-version:
8+
description: Python version to use
9+
required: false
10+
default: "3.12"
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Install uv
15+
uses: ./.github/actions/install-uv
16+
with:
17+
python-version: ${{ inputs.python-version }}
18+
19+
- name: Download wheel
20+
uses: actions/download-artifact@v4
21+
with:
22+
name: ${{ inputs.artifact-name }}
23+
path: dist
24+
25+
- name: Run tests
26+
shell: bash
27+
run: |
28+
WHEEL_PATH=$(ls dist/*.whl)
29+
uv venv
30+
uv sync --no-install-project --no-default-groups --group=test
31+
uv pip install --force-reinstall "$WHEEL_PATH"
32+
uv run --no-sync pytest tests/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Upload wheels
2+
description: Upload wheels artifact
3+
inputs:
4+
name:
5+
required: true
6+
path:
7+
required: true
8+
runs:
9+
using: "composite"
10+
steps:
11+
- name: Upload wheel
12+
uses: actions/upload-artifact@v4
13+
with:
14+
name: ${{ inputs.name }}
15+
path: ${{ inputs.path }}

.github/workflows/build-test.yml

Lines changed: 18 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,14 @@ on:
66
- main
77
tags:
88
- "*"
9-
pull_request:
109
workflow_dispatch:
1110

1211
permissions:
1312
contents: read
1413

1514
jobs:
1615
lint:
17-
name: Lint
18-
runs-on: ubuntu-24.04
19-
steps:
20-
- uses: actions/checkout@v6
21-
- uses: astral-sh/ruff-action@v3
22-
- run: |
23-
ruff check
24-
ruff format --check
16+
uses: ./.github/workflows/lint.yml
2517

2618
rust_tests:
2719
name: Rust tests - ${{ matrix.platform.name }}
@@ -44,48 +36,10 @@ jobs:
4436
runner: macos-15
4537
steps:
4638
- uses: actions/checkout@v6
47-
- name: Cache Rust build
48-
uses: actions/cache@v4
49-
with:
50-
path: |
51-
target
52-
~/.cargo/registry
53-
~/.cargo/git
54-
key: ${{ runner.os }}-test-${{ runner.arch }}-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
55-
restore-keys: |
56-
${{ runner.os }}-test-${{ runner.arch }}-
57-
58-
- name: Install uv
59-
uses: astral-sh/setup-uv@v7
60-
with:
61-
version: "0.9.11"
62-
enable-cache: true
63-
cache-dependency-glob: "**/uv.lock"
64-
# python-version: "3.12"
65-
66-
- name: Install required python dependencies
67-
run: uv sync --no-install-project
68-
shell: bash
69-
70-
- name: Run cargo tests
71-
run: |
72-
# pyo3 and uv do not work well together...
73-
PY_LIBDIR=$(uv run --no-sync python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
74-
echo "Python libdir: $PY_LIBDIR"
75-
# setting LD_LIBRARY_PATH for Linux: https://github.com/astral-sh/uv/issues/11006#issuecomment-2672486381
76-
export LD_LIBRARY_PATH="$PY_LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" # LINUX
77-
if [[ "$RUNNER_OS" == "Windows" ]]; then
78-
uv run --no-sync python -c "import sys; print(sys.path)"
79-
uv run --no-sync where python
80-
export PYTHONPATH="$(echo .venv/Lib/site-packages)"
81-
else
82-
# setting PYTHONHOME and PYTHONPATH seem to be the best solution for macOS at the moment
83-
# https://github.com/PyO3/pyo3/issues/1741#issuecomment-955805634
84-
export PYTHONHOME="$(uv run --no-sync python -c 'import sys; print(sys.base_prefix)')" # MACOS
85-
export PYTHONPATH="$(echo .venv/lib/python*/site-packages)" # MACOS
86-
fi
87-
uv run --no-sync cargo test --no-default-features
88-
shell: bash
39+
- uses: ./.github/actions/cache-rust-build
40+
- uses: ./.github/actions/install-uv
41+
- uses: ./.github/actions/install-python-deps
42+
- uses: ./.github/actions/run-cargo-tests
8943

9044
build:
9145
needs: rust_tests
@@ -141,27 +95,14 @@ jobs:
14195
is-musl: false
14296
steps:
14397
- uses: actions/checkout@v6
144-
- name: Cache Rust build
145-
uses: actions/cache@v4
146-
with:
147-
path: |
148-
target
149-
~/.cargo/registry
150-
~/.cargo/git
151-
key: ${{ runner.os }}-build-${{ matrix.platform.name }}-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml') }}
152-
restore-keys: |
153-
${{ runner.os }}-build-${{ matrix.platform.name }}-
154-
- name: Build wheels
155-
uses: PyO3/maturin-action@v1
98+
- uses: ./.github/actions/cache-rust-build
99+
- uses: ./.github/actions/build-wheel
156100
with:
157-
maturin-version: 1.9.6
158101
target: ${{ matrix.platform.target }}
159102
args: --release --out dist --find-interpreter
160103
manylinux: ${{ matrix.platform.manylinux }}
161-
container: ${{ matrix.platform.is-musl == true && 'off' || '' }}
162104
before-script-linux: ${{ matrix.platform.before-script }}
163-
- name: Upload wheels
164-
uses: actions/upload-artifact@v4
105+
- uses: ./.github/actions/upload-wheels
165106
with:
166107
name: wheels-${{ matrix.platform.name }}
167108
path: dist
@@ -171,13 +112,12 @@ jobs:
171112
steps:
172113
- uses: actions/checkout@v6
173114
- name: Build sdist
174-
uses: PyO3/maturin-action@v1
115+
uses: ./.github/actions/build-wheel
175116
with:
176-
maturin-version: 1.9.6
177117
command: sdist
178118
args: --out dist
179119
- name: Upload sdist
180-
uses: actions/upload-artifact@v4
120+
uses: ./.github/actions/upload-wheels
181121
with:
182122
name: wheels-sdist
183123
path: dist
@@ -265,44 +205,17 @@ jobs:
265205
python-version: "3.10"
266206
is-min-deps: true
267207
steps:
268-
# Use the test composite action
269208
- uses: actions/checkout@v6
270-
271-
- name: Install uv
272-
uses: astral-sh/setup-uv@v7
209+
- uses: ./.github/actions/install-uv
273210
with:
274-
version: "0.9.11"
275-
enable-cache: "true"
276-
cache-dependency-glob: "**/uv.lock"
277211
python-version: ${{ matrix.config.python-version }}
278-
279-
- name: Download wheels
280-
uses: actions/download-artifact@v4
212+
- uses: ./.github/actions/download-wheels
281213
with:
282214
name: wheels-${{ matrix.config.platform-name }}
283215
path: dist
284-
285-
# Regular tests (non-musl platforms)
286-
- name: Run regular tests
287-
if: ${{ !matrix.config.is-min-deps && !matrix.config.is-musl }}
288-
shell: bash
289-
run: |
290-
WHEEL_PATH=$(ls dist/*.whl)
291-
uv venv
292-
uv sync --no-install-project --no-default-groups --group=test
293-
uv pip install --force-reinstall "$WHEEL_PATH"
294-
uv run --no-sync pytest tests/
295-
296-
# Minimum dependencies test
297-
- name: Run tests with minimum dependencies
298-
if: ${{ matrix.config.is-min-deps }}
299-
shell: bash
300-
run: |
301-
WHEEL_PATH=$(ls dist/*.whl)
302-
uv venv
303-
uv sync --resolution lowest-direct --no-install-project --no-default-groups --group=test
304-
uv pip install --no-deps --force-reinstall "$WHEEL_PATH"
305-
uv run --no-sync --no-default-groups --group=test pytest tests/
216+
- uses: ./.github/actions/run-python-tests
217+
with:
218+
min-deps: ${{ matrix.config.is-min-deps }}
306219

307220
test-musl:
308221
needs: build
@@ -317,25 +230,13 @@ jobs:
317230
run: |
318231
apk add tar python3 py3-pip py3-psutil gcc python3-dev musl-dev linux-headers
319232
320-
- name: Install uv
321-
uses: astral-sh/setup-uv@v7
233+
- uses: ./.github/actions/install-uv
322234
with:
323-
version: "0.9.11"
324-
enable-cache: "true"
325-
cache-dependency-glob: "**/uv.lock"
326235
python-version: "3.12"
327-
328-
- name: Download wheels
329-
uses: actions/download-artifact@v4
236+
- uses: ./.github/actions/download-wheels
330237
with:
331238
name: wheels-linux-musl-x86_64
332239
path: dist
333240

334241
- name: Run musl tests
335-
shell: sh
336-
run: |
337-
WHEEL_PATH=$(ls dist/*.whl)
338-
uv venv
339-
uv sync --no-install-project --no-default-groups --group=test
340-
uv pip install --force-reinstall "$WHEEL_PATH"
341-
uv run --no-sync pytest tests/
242+
uses: ./.github/actions/run-python-tests

0 commit comments

Comments
 (0)