1+ name : Test coverage
2+ on :
3+ workflow_dispatch :
4+ inputs :
5+ git_ref :
6+ type : string
7+ description : Git ref of the DuckDB python package
8+ default : refs/heads/main
9+ required : true
10+ duckdb_git_ref :
11+ type : string
12+ description : Git ref of DuckDB
13+ testsuite :
14+ type : choice
15+ description : Testsuite to run ('all' or 'fast')
16+ default : all
17+ required : true
18+ options :
19+ - all
20+ - fast
21+ workflow_call :
22+ inputs :
23+ git_ref :
24+ type : string
25+ description : Git ref of the DuckDB python package
26+ required : true
27+ duckdb_git_ref :
28+ type : string
29+ testsuite :
30+ type : string
31+ description : Testsuite to run ('all' or 'fast')
32+ required : true
33+ default : all
34+
35+ concurrency :
36+ group : coverage-${{ github.workflow }}-${{ github.ref }}
37+ cancel-in-progress : true
38+
39+ jobs :
40+ generate_coverage_reports :
41+ name : Generate code coverage reports for both Python and C++ code
42+ runs-on : ubuntu-24.04
43+ env : { COVERAGE: 1 }
44+ outputs :
45+ summary_py : ${{ steps.py_coverage.outputs.summary }}
46+ summary_cpp : ${{ steps.cpp_coverage.outputs.summary }}
47+ steps :
48+
49+ - uses : actions/checkout@v4
50+ with :
51+ ref : ${{ inputs.git_ref }}
52+ fetch-depth : 0
53+ submodules : true
54+
55+ - name : Checkout DuckDB to provided ref
56+ if : ${{ inputs.duckdb_git_ref != '' }}
57+ shell : bash
58+ run : |
59+ cd external/duckdb
60+ git fetch origin
61+ git checkout ${{ inputs.duckdb_git_ref }}
62+
63+ - name : Set DuckDB to HEAD if no ref provided
64+ if : ${{ inputs.duckdb_git_ref == '' }}
65+ run : git submodule update --remote
66+
67+ - name : Install Ccache
68+ shell : bash
69+ run : |
70+ sudo apt-get update
71+ sudo apt-get -y install ccache
72+
73+ - name : Install Astral UV and enable the cache
74+ uses : astral-sh/setup-uv@v6
75+ with :
76+ version : " 0.7.14"
77+ python-version : 3.9
78+ enable-cache : true
79+ cache-suffix : -${{ github.workflow }}
80+
81+ - name : Run tests with coverage
82+ shell : bash
83+ run : |
84+ if [[ "${{ inputs.testsuite }}" == "all" ]]; then
85+ uv run coverage run -m pytest ./tests --ignore=./tests/stubs
86+ elif [[ "${{ inputs.testsuite }}" == "fast" ]]; then
87+ uv run coverage run -m pytest ./tests/fast
88+ else
89+ echo "Invalid testsuite!"
90+ exit 1
91+ fi
92+
93+ - name : Get Python coverage data
94+ id : py_coverage
95+ shell : bash
96+ run : |
97+ # save HTML report in coverage-python
98+ uv run coverage html -d coverage-python
99+ # save markdown summary in step output
100+ echo "summary<<EOF" >> $GITHUB_OUTPUT
101+ uv run coverage report --format=markdown >> $GITHUB_OUTPUT
102+ echo "EOF" >> $GITHUB_OUTPUT
103+
104+ - name : Upload Python coverage report
105+ uses : actions/upload-artifact@v4
106+ with :
107+ name : coverage-report-python
108+ path : coverage-python
109+
110+ - name : Get C++ coverage data
111+ id : cpp_coverage
112+ shell : bash
113+ run : |
114+ mkdir coverage-cpp
115+ uv run gcovr \
116+ --gcov-ignore-errors all \
117+ --root "$PWD" \
118+ --filter "${PWD}/src/duckdb_py" \
119+ --exclude '.*/\.cache/.*' \
120+ --gcov-exclude '.*/\.cache/.*' \
121+ --gcov-exclude '.*/external/.*' \
122+ --gcov-exclude '.*/site-packages/.*' \
123+ --exclude-unreachable-branches \
124+ --exclude-throw-branches \
125+ --html --html-details -o coverage-cpp/index.html \
126+ build/coverage/src/duckdb_py \
127+ --print-summary > cpp_summary.txt
128+ # save the summary in the output
129+ echo "summary<<EOF" >> $GITHUB_OUTPUT
130+ cat cpp_summary.txt >> $GITHUB_OUTPUT
131+ echo "EOF" >> $GITHUB_OUTPUT
132+
133+ - name : Upload C++ coverage report
134+ uses : actions/upload-artifact@v4
135+ with :
136+ name : coverage-report-cpp
137+ path : coverage-cpp
138+
139+ summary :
140+ name : Coverage Summary
141+ runs-on : ubuntu-24.04
142+ needs : [generate_coverage_reports]
143+ env :
144+ SUMMARY_PY : ${{ needs.generate_coverage_reports.outputs.summary_py }}
145+ SUMMARY_CPP : ${{ needs.generate_coverage_reports.outputs.summary_cpp }}
146+ if : always()
147+ steps :
148+ - name : Summarize
149+ shell : bash
150+ run : |
151+ echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
152+ echo "### Python Coverage Summary" >> $GITHUB_STEP_SUMMARY
153+ echo "$SUMMARY_PY" >> $GITHUB_STEP_SUMMARY
154+ echo "### C++ Coverage Summary" >> $GITHUB_STEP_SUMMARY
155+ echo '```' >> $GITHUB_STEP_SUMMARY
156+ echo "$SUMMARY_CPP" >> $GITHUB_STEP_SUMMARY
157+ echo '```' >> $GITHUB_STEP_SUMMARY
0 commit comments