Skip to content

Commit fdec698

Browse files
Add code coverage report
1 parent 2b8093a commit fdec698

4 files changed

Lines changed: 62 additions & 3 deletions

File tree

.github/workflows/codacy.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Codacy Coverage Reporter
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Tests
7+
types:
8+
- completed
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
report-coverage:
16+
if: github.repository == 'everoddandeven/monero-python'
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Download coverage report
20+
uses: actions/download-artifact@v5
21+
with:
22+
name: coverage-report
23+
github-token: ${{ secrets.API_GITHUB }}
24+
run-id: ${{ github.event.workflow_run.id }}
25+
26+
- name: Run codacy-coverage-reporter
27+
uses: codacy/codacy-coverage-reporter-action@v1
28+
with:
29+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
30+
coverage-reports: coverage.info

.github/workflows/test.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Install dependencies
2222
run: |
2323
sudo apt update
24-
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
24+
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
2525
pip3 install pybind11-stubgen pytest --break-system-packages
2626
2727
- name: Install expat
@@ -106,12 +106,19 @@ jobs:
106106
- name: Install monero-python
107107
run: |
108108
mkdir -p build
109-
pip3 install -vvv .
109+
export CFLAGS="--coverage -O0 -g"
110+
export CXXFLAGS="--coverage -O0 -g"
111+
export LDFLAGS="--coverage"
112+
COVERAGE=1 pip3 install -vvv .
110113
111114
- name: Setup test environment
112115
run: |
113116
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2
114117
118+
- name: Reset coverage counters
119+
run: |
120+
lcov --directory . --zerocounters
121+
115122
- name: Run tests
116123
env:
117124
IN_CONTAINER: "true"
@@ -121,3 +128,15 @@ jobs:
121128
- name: Cleanup test environment
122129
if: always()
123130
run: docker compose -f tests/docker-compose.yml down -v
131+
132+
- name: Generate coverage report
133+
run: |
134+
lcov --capture --directory . --ignore-errors mismatch,mismatch,inconsistent,source,source,gcov,gcov --output-file coverage_full.info
135+
lcov --ignore-errors unused,unused --remove coverage_full.info '/usr/*' '*/external/*' '*/pybind11/*' '*monero-cpp/*' '*monero-project/*' --output-file coverage.info
136+
137+
- name: Upload coverage report
138+
uses: actions/upload-artifact@v4
139+
with:
140+
name: coverage-report
141+
path: coverage.info
142+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ test_wallets
1111
.github/instructions/codacy.instructions.md
1212
.idea
1313
.codacy
14+
coverage*

setup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import pybind11
22
import sys
3+
import os
34

45
from setuptools import setup
56
from pathlib import Path
67
from pybind11.setup_helpers import Pybind11Extension, build_ext
78

9+
coverage = os.environ.get("COVERAGE") == "1"
810
this_dir = Path(__file__).parent.resolve()
11+
extra_compile_args = ['/std:c++17'] if sys.platform == "win32" else ['-std=c++17']
12+
extra_link_args = []
13+
14+
if coverage:
15+
extra_compile_args += ['-O0', '-g', '--coverage']
16+
extra_link_args += ['--coverage']
917

1018
ext_modules = [
1119
Pybind11Extension(
@@ -39,7 +47,8 @@
3947
],
4048
libraries=['monero-cpp'],
4149
language='c++',
42-
extra_compile_args=['/std:c++17'] if sys.platform == "win32" else ['-std=c++17'],
50+
extra_compile_args=extra_compile_args,
51+
extra_link_args=extra_link_args
4352
),
4453
]
4554

0 commit comments

Comments
 (0)