-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathaction.yml
More file actions
202 lines (165 loc) · 6.68 KB
/
Copy pathaction.yml
File metadata and controls
202 lines (165 loc) · 6.68 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: python-maturin-pre-merge
description: Python pre-merge testing with maturin github iggy actions
inputs:
task:
description: "Task to run (lint, test, build)"
required: true
runs:
using: "composite"
steps:
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Setup Rust with cache
uses: ./.github/actions/utils/setup-rust-with-cache
- name: Install cargo-llvm-cov
if: inputs.task == 'test'
uses: taiki-e/install-action@v2
with:
tool: cargo-llvm-cov
- name: Install uv
uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
- name: Cache uv
uses: actions/cache@v5
with:
path: ~/.cache/uv
key: uv-${{ runner.os }}-${{ hashFiles('examples/python/uv.lock', 'foreign/python/uv.lock', 'bdd/python/uv.lock') }}
- name: Install dependencies
shell: bash
run: |
cd foreign/python
uv sync --frozen --extra dev --extra testing --extra testing-docker
- name: Lint and format check
if: inputs.task == 'lint'
run: |
# Build list of directories to check
DIR_SDK="${GITHUB_WORKSPACE}/foreign/python"
DIR_BDD="${GITHUB_WORKSPACE}/bdd/python"
DIR_EXAMPLES="${GITHUB_WORKSPACE}/examples/python"
# Collect all Python directories that exist
DIRS_TO_CHECK="$DIR_SDK"
[ -d "$DIR_BDD" ] && DIRS_TO_CHECK="$DIRS_TO_CHECK $DIR_BDD"
[ -d "$DIR_EXAMPLES" ] && DIRS_TO_CHECK="$DIRS_TO_CHECK $DIR_EXAMPLES"
cd foreign/python
echo "Directories to check: $DIRS_TO_CHECK"
echo "ruff version: $(uv run ruff --version)"
echo "Running ruff check..."
uv run ruff check $DIRS_TO_CHECK
echo "Running ruff format --check..."
uv run ruff format --check $DIRS_TO_CHECK
# mypy only for the SDK (has type stubs)
echo "Running mypy on SDK..."
uv run mypy --explicit-package-bases "$DIR_SDK"
echo "mypy version: $(uv run mypy --version)"
echo "Running pyrefly on SDK..."
uv run pyrefly check
echo "pyrefly version: $(uv run pyrefly --version)"
shell: bash
- name: Build Python wheel with coverage instrumentation
if: inputs.task == 'test'
run: |
cd foreign/python
source <(cargo llvm-cov show-env --sh)
export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
# Propagate LLVM_PROFILE_FILE so the test step can write profraw data
echo "LLVM_PROFILE_FILE=${LLVM_PROFILE_FILE}" >> $GITHUB_ENV
cargo llvm-cov clean --workspace
echo "Building Python wheel with coverage instrumentation..."
uv run --no-sync maturin develop
shell: bash
- name: Build Python wheel
if: inputs.task == 'build'
run: |
cd foreign/python
# Build the module
echo "Building Python wheel..."
uv run maturin build -o dist
# List built artifacts
echo ""
echo "Build artifacts:"
ls -la dist/
shell: bash
- name: Start Iggy server
if: inputs.task == 'test'
id: iggy
uses: ./.github/actions/utils/server-start
continue-on-error: true
- name: Run Python integration tests
if: inputs.task == 'test' && steps.iggy.outcome == 'success'
run: |
cd foreign/python
echo "Running integration tests with Iggy server at ${{ steps.iggy.outputs.address }}..."
# Run all tests with server connection
# --no-sync prevents uv from re-syncing the venv which would
# overwrite the coverage-instrumented .so with a non-instrumented one
IGGY_SERVER_HOST=127.0.0.1 \
IGGY_SERVER_TCP_PORT=8090 \
uv run --no-sync pytest tests/ -v \
--junitxml=../../reports/python-junit.xml \
--tb=short \
--capture=no || TEST_EXIT_CODE=$?
# Exit with test result
exit ${TEST_EXIT_CODE:-0}
shell: bash
- name: Run Python unit tests only (fallback)
if: inputs.task == 'test' && steps.iggy.outcome != 'success'
run: |
cd foreign/python
echo "⚠️ Server failed to start, running unit tests only..."
# Run unit tests only (exclude integration tests)
uv run --no-sync pytest tests/ -v \
-m "not integration" \
--junitxml=../../reports/python-junit.xml \
--tb=short || TEST_EXIT_CODE=$?
# Exit with test result (allow some failures in unit-only mode)
exit ${TEST_EXIT_CODE:-0}
shell: bash
- name: Stop Iggy server
if: always() && inputs.task == 'test'
uses: ./.github/actions/utils/server-stop
with:
pid-file: ${{ steps.iggy.outputs.pid_file }}
log-file: ${{ steps.iggy.outputs.log_file }}
- name: Generate coverage report
if: inputs.task == 'test'
run: |
mkdir -p reports
cd foreign/python
source <(cargo llvm-cov show-env --sh)
export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
cargo llvm-cov report --lcov \
--ignore-filename-regex='(\.cargo/|/rustc/|/core/)' \
--output-path ../../reports/python-coverage.lcov
# Fix paths: cargo-llvm-cov outputs paths relative to the crate root (src/...)
# but Codecov expects paths relative to the repo root (foreign/python/src/...)
sed -i 's|^SF:src/|SF:foreign/python/src/|' ../../reports/python-coverage.lcov
echo "Coverage report generated: $(wc -l < ../../reports/python-coverage.lcov) lines"
shell: bash
- name: Upload test artifacts
if: always() && inputs.task == 'test'
uses: actions/upload-artifact@v7
with:
name: python-test-results-${{ github.run_id }}-${{ github.run_attempt }}
path: |
reports/python-junit.xml
reports/python-coverage.lcov
foreign/python/dist/*.whl
retention-days: 7
if-no-files-found: ignore