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 : Install Ccache
64+ shell : bash
65+ run : |
66+ sudo apt-get update
67+ sudo apt-get -y install ccache
68+
69+ - name : Install Astral UV and enable the cache
70+ uses : astral-sh/setup-uv@v6
71+ with :
72+ version : " 0.7.14"
73+ python-version : 3.9
74+ enable-cache : true
75+ cache-suffix : -${{ github.workflow }}
76+
77+ - name : Run tests with coverage
78+ shell : bash
79+ run : |
80+ if [[ "${{ inputs.testsuite }}" == "all" ]]; then
81+ uv run coverage run -m pytest ./tests --ignore=./tests/stubs
82+ elif [[ "${{ inputs.testsuite }}" == "fast" ]]; then
83+ uv run coverage run -m pytest ./tests/fast
84+ else
85+ echo "Invalid testsuite!"
86+ exit 1
87+ fi
88+
89+ - name : Get Python coverage data
90+ id : py_coverage
91+ shell : bash
92+ run : |
93+ # save HTML report in coverage-python
94+ uv run coverage html -d coverage-python
95+ # save markdown summary in step output
96+ echo "summary<<EOF" >> $GITHUB_OUTPUT
97+ uv run coverage report --format=markdown >> $GITHUB_OUTPUT
98+ echo "EOF" >> $GITHUB_OUTPUT
99+
100+ - name : Upload Python coverage report
101+ uses : actions/upload-artifact@v4
102+ with :
103+ name : coverage-report-python
104+ path : coverage-python
105+
106+ - name : Get C++ coverage data
107+ id : cpp_coverage
108+ shell : bash
109+ run : |
110+ mkdir coverage-cpp
111+ uv run gcovr \
112+ --gcov-ignore-errors all \
113+ --root "$PWD" \
114+ --filter "${PWD}/src/duckdb_py" \
115+ --exclude '.*/\.cache/.*' \
116+ --gcov-exclude '.*/\.cache/.*' \
117+ --gcov-exclude '.*/external/.*' \
118+ --gcov-exclude '.*/site-packages/.*' \
119+ --exclude-unreachable-branches \
120+ --exclude-throw-branches \
121+ --html --html-details -o coverage-cpp/index.html \
122+ build/coverage/src/duckdb_py \
123+ --print-summary > cpp_summary.txt
124+ # save the summary in the output
125+ echo "summary<<EOF" >> $GITHUB_OUTPUT
126+ cat cpp_summary.txt >> $GITHUB_OUTPUT
127+ echo "EOF" >> $GITHUB_OUTPUT
128+
129+ - name : Upload C++ coverage report
130+ uses : actions/upload-artifact@v4
131+ with :
132+ name : coverage-report-cpp
133+ path : coverage-cpp
134+
135+ summary :
136+ name : Coverage Summary
137+ runs-on : ubuntu-24.04
138+ needs : [generate_coverage_reports]
139+ env :
140+ SUMMARY_PY : ${{ needs.generate_coverage_reports.outputs.summary_py }}
141+ SUMMARY_CPP : ${{ needs.generate_coverage_reports.outputs.summary_cpp }}
142+ if : always()
143+ steps :
144+ - name : Summarize
145+ shell : bash
146+ run : |
147+ echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
148+ echo "### Python Coverage Summary" >> $GITHUB_STEP_SUMMARY
149+ echo "$SUMMARY_PY" >> $GITHUB_STEP_SUMMARY
150+ echo "### C++ Coverage Summary" >> $GITHUB_STEP_SUMMARY
151+ echo '```' >> $GITHUB_STEP_SUMMARY
152+ echo "$SUMMARY_CPP" >> $GITHUB_STEP_SUMMARY
153+ echo '```' >> $GITHUB_STEP_SUMMARY
0 commit comments