From fdec6986311f8e902f10ab34ecb9ba3d3648bd89 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Thu, 15 Jan 2026 18:58:03 +0100 Subject: [PATCH] Add code coverage report --- .github/workflows/codacy.yml | 30 ++++++++++++++++++++++++++++++ .github/workflows/test.yml | 23 +++++++++++++++++++++-- .gitignore | 1 + setup.py | 11 ++++++++++- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/codacy.yml diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml new file mode 100644 index 0000000..0a7c861 --- /dev/null +++ b/.github/workflows/codacy.yml @@ -0,0 +1,30 @@ +name: Codacy Coverage Reporter + +on: + workflow_run: + workflows: + - Tests + types: + - completed + workflow_dispatch: + +permissions: + contents: read + +jobs: + report-coverage: + if: github.repository == 'everoddandeven/monero-python' + runs-on: ubuntu-latest + steps: + - name: Download coverage report + uses: actions/download-artifact@v5 + with: + name: coverage-report + github-token: ${{ secrets.API_GITHUB }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Run codacy-coverage-reporter + uses: codacy/codacy-coverage-reporter-action@v1 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: coverage.info diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 675b16f..05ff4d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: - name: Install dependencies run: | sudo apt update - sudo apt install -y build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz git curl autoconf libtool gperf nettle-dev libevent-dev debhelper python3-all python3-pip python3-pybind11 python3-pytest python3-pytest-rerunfailures + sudo apt install -y build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz git curl autoconf libtool gperf nettle-dev libevent-dev debhelper python3-all python3-pip python3-pybind11 python3-pytest python3-pytest-rerunfailures lcov pip3 install pybind11-stubgen pytest --break-system-packages - name: Install expat @@ -106,12 +106,19 @@ jobs: - name: Install monero-python run: | mkdir -p build - pip3 install -vvv . + export CFLAGS="--coverage -O0 -g" + export CXXFLAGS="--coverage -O0 -g" + export LDFLAGS="--coverage" + COVERAGE=1 pip3 install -vvv . - name: Setup test environment run: | docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 + - name: Reset coverage counters + run: | + lcov --directory . --zerocounters + - name: Run tests env: IN_CONTAINER: "true" @@ -121,3 +128,15 @@ jobs: - name: Cleanup test environment if: always() run: docker compose -f tests/docker-compose.yml down -v + + - name: Generate coverage report + run: | + lcov --capture --directory . --ignore-errors mismatch,mismatch,inconsistent,source,source,gcov,gcov --output-file coverage_full.info + lcov --ignore-errors unused,unused --remove coverage_full.info '/usr/*' '*/external/*' '*/pybind11/*' '*monero-cpp/*' '*monero-project/*' --output-file coverage.info + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage.info + diff --git a/.gitignore b/.gitignore index 7e2ff25..48b56f5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ test_wallets .github/instructions/codacy.instructions.md .idea .codacy +coverage* diff --git a/setup.py b/setup.py index c5090b1..388e62a 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,19 @@ import pybind11 import sys +import os from setuptools import setup from pathlib import Path from pybind11.setup_helpers import Pybind11Extension, build_ext +coverage = os.environ.get("COVERAGE") == "1" this_dir = Path(__file__).parent.resolve() +extra_compile_args = ['/std:c++17'] if sys.platform == "win32" else ['-std=c++17'] +extra_link_args = [] + +if coverage: + extra_compile_args += ['-O0', '-g', '--coverage'] + extra_link_args += ['--coverage'] ext_modules = [ Pybind11Extension( @@ -39,7 +47,8 @@ ], libraries=['monero-cpp'], language='c++', - extra_compile_args=['/std:c++17'] if sys.platform == "win32" else ['-std=c++17'], + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args ), ]