This is an automated email from the ASF dual-hosted git repository.
hgruszecki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iggy.git
The following commit(s) were added to refs/heads/master by this push:
new 13ff0f53a fix(ci): use cargo-llvm-cov properly for Python SDK coverage
in Codecov (#2867)
13ff0f53a is described below
commit 13ff0f53a8f13144f7f0a694b1e17762a42c9a59
Author: Atharva Lade <[email protected]>
AuthorDate: Wed Mar 4 14:35:44 2026 -0600
fix(ci): use cargo-llvm-cov properly for Python SDK coverage in Codecov
(#2867)
---
.../actions/python-maturin/pre-merge/action.yml | 50 +++++++++-------------
.github/workflows/post-merge.yml | 47 +++++++++-----------
2 files changed, 41 insertions(+), 56 deletions(-)
diff --git a/.github/actions/python-maturin/pre-merge/action.yml
b/.github/actions/python-maturin/pre-merge/action.yml
index b6134e4b3..ee0d08bab 100644
--- a/.github/actions/python-maturin/pre-merge/action.yml
+++ b/.github/actions/python-maturin/pre-merge/action.yml
@@ -34,10 +34,11 @@ runs:
- name: Setup Rust with cache
uses: ./.github/actions/utils/setup-rust-with-cache
- - name: Install llvm-tools for coverage
+ - name: Install cargo-llvm-cov
if: inputs.task == 'test'
- run: rustup component add llvm-tools-preview
- shell: bash
+ uses: taiki-e/install-action@v2
+ with:
+ tool: cargo-llvm-cov
- name: Install uv
uses: astral-sh/setup-uv@v7
@@ -92,15 +93,15 @@ runs:
if: inputs.task == 'test'
run: |
cd foreign/python
- mkdir -p target/coverage
+ source <(cargo llvm-cov show-env --sh)
+ export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
- # Instrument Rust code with coverage and set profraw output path
- export RUSTFLAGS="-C instrument-coverage"
- export LLVM_PROFILE_FILE="$(pwd)/target/coverage/%p-%4m.profraw"
+ # 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 maturin develop --release
+ uv run --no-sync maturin develop
shell: bash
- name: Build Python wheel
@@ -132,9 +133,11 @@ runs:
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 pytest tests/ -v \
+ uv run --no-sync pytest tests/ -v \
--junitxml=../../reports/python-junit.xml \
--tb=short \
--capture=no || TEST_EXIT_CODE=$?
@@ -151,7 +154,7 @@ runs:
echo "⚠️ Server failed to start, running unit tests only..."
# Run unit tests only (exclude integration tests)
- uv run pytest tests/ -v \
+ uv run --no-sync pytest tests/ -v \
-m "not integration" \
--junitxml=../../reports/python-junit.xml \
--tb=short || TEST_EXIT_CODE=$?
@@ -172,27 +175,16 @@ runs:
run: |
mkdir -p reports
cd foreign/python
+ source <(cargo llvm-cov show-env --sh)
+ export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
- PROFRAW_COUNT=$(find target/coverage -name '*.profraw' 2>/dev/null |
wc -l)
- echo "Found ${PROFRAW_COUNT} profraw file(s)"
-
- if [ "${PROFRAW_COUNT}" -eq 0 ]; then
- echo "No profraw files found, skipping coverage report"
- exit 0
- fi
-
- LLVM_PROFDATA=$(find "$(rustc --print sysroot)" -name 'llvm-profdata'
-type f | head -1)
- LLVM_COV=$(find "$(rustc --print sysroot)" -name 'llvm-cov' -type f |
head -1)
- SHARED_LIB=$(find target/release -name 'libapache_iggy*.so'
2>/dev/null | head -1)
-
- "${LLVM_PROFDATA}" merge -sparse target/coverage/*.profraw -o
target/coverage/merged.profdata
+ cargo llvm-cov report --lcov \
+ --ignore-filename-regex='(\.cargo/|/rustc/|/core/)' \
+ --output-path ../../reports/python-coverage.lcov
- "${LLVM_COV}" export \
- --format=lcov \
- --instr-profile=target/coverage/merged.profdata \
- --ignore-filename-regex='(/.cargo/registry|/rustc/)' \
- "${SHARED_LIB}" \
- > ../../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
diff --git a/.github/workflows/post-merge.yml b/.github/workflows/post-merge.yml
index 7a0964fa7..2f9a6fcf6 100644
--- a/.github/workflows/post-merge.yml
+++ b/.github/workflows/post-merge.yml
@@ -362,8 +362,10 @@ jobs:
with:
save-cache: "false"
- - name: Install llvm-tools for coverage
- run: rustup component add llvm-tools-preview
+ - name: Install cargo-llvm-cov
+ uses: taiki-e/install-action@v2
+ with:
+ tool: cargo-llvm-cov
- name: Install uv
uses: astral-sh/setup-uv@v7
@@ -376,15 +378,16 @@ jobs:
- name: Build Python wheel with coverage instrumentation
run: |
cd foreign/python
- mkdir -p target/coverage
+ source <(cargo llvm-cov show-env --sh)
+ export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
- # Instrument Rust code with coverage and set profraw output path
- export RUSTFLAGS="-C instrument-coverage"
- export LLVM_PROFILE_FILE="$(pwd)/target/coverage/%p-%4m.profraw"
+ # 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 maturin develop --release
+ uv run --no-sync maturin develop
+ shell: bash
- name: Start Iggy server
id: iggy
@@ -395,7 +398,7 @@ jobs:
cd foreign/python
IGGY_SERVER_HOST=127.0.0.1 \
IGGY_SERVER_TCP_PORT=8090 \
- uv run pytest tests/ -v \
+ uv run --no-sync pytest tests/ -v \
--junitxml=../../reports/python-junit.xml \
--tb=short \
--capture=no
@@ -411,29 +414,19 @@ jobs:
run: |
mkdir -p reports
cd foreign/python
+ source <(cargo llvm-cov show-env --sh)
+ export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
- PROFRAW_COUNT=$(find target/coverage -name '*.profraw' 2>/dev/null |
wc -l)
- echo "Found ${PROFRAW_COUNT} profraw file(s)"
+ cargo llvm-cov report --lcov \
+ --ignore-filename-regex='(\.cargo/|/rustc/|/core/)' \
+ --output-path ../../reports/python-coverage.lcov
- if [ "${PROFRAW_COUNT}" -eq 0 ]; then
- echo "No profraw files found, skipping coverage report"
- exit 0
- fi
-
- LLVM_PROFDATA=$(find "$(rustc --print sysroot)" -name
'llvm-profdata' -type f | head -1)
- LLVM_COV=$(find "$(rustc --print sysroot)" -name 'llvm-cov' -type f
| head -1)
- SHARED_LIB=$(find target/release -name 'libapache_iggy*.so'
2>/dev/null | head -1)
-
- "${LLVM_PROFDATA}" merge -sparse target/coverage/*.profraw -o
target/coverage/merged.profdata
-
- "${LLVM_COV}" export \
- --format=lcov \
- --instr-profile=target/coverage/merged.profdata \
- --ignore-filename-regex='(/.cargo/registry|/rustc/)' \
- "${SHARED_LIB}" \
- > ../../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 to Codecov
uses: codecov/codecov-action@v5