Skip to content

Commit 56732cd

Browse files
Add code coverage reporting (#101)
1 parent 1ea0bca commit 56732cd

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

‎.github/workflows/tests.yml‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,123 @@ jobs:
259259
livekit-server.log
260260
if-no-files-found: ignore
261261
retention-days: 7
262+
263+
# ============================================================================
264+
# Code Coverage (Linux only)
265+
# Runs a debug build through gcov/lcov and generates an inline action summary
266+
# alongside an HTML report of unit test coverage.
267+
# ============================================================================
268+
coverage:
269+
name: Code Coverage
270+
runs-on: ubuntu-latest
271+
272+
steps:
273+
- name: Checkout (with submodules)
274+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
275+
with:
276+
submodules: recursive
277+
fetch-depth: 1
278+
279+
- name: Pull LFS files
280+
run: git lfs pull
281+
282+
# ---------- OS deps ----------
283+
- name: Install deps
284+
run: |
285+
set -eux
286+
sudo apt-get update
287+
sudo apt-get install -y \
288+
build-essential cmake ninja-build pkg-config \
289+
llvm-dev libclang-dev clang \
290+
libva-dev libdrm-dev libgbm-dev libx11-dev libgl1-mesa-dev \
291+
libxext-dev libxcomposite-dev libxdamage-dev libxfixes-dev \
292+
libxrandr-dev libxi-dev libxkbcommon-dev \
293+
libasound2-dev libpulse-dev \
294+
libssl-dev \
295+
libprotobuf-dev protobuf-compiler \
296+
libabsl-dev \
297+
libwayland-dev libdecor-0-dev
298+
pip install --break-system-packages gcovr
299+
300+
# ---------- Rust toolchain ----------
301+
- name: Install Rust (stable)
302+
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
303+
with:
304+
toolchain: stable
305+
306+
# ---------- Cache Cargo ----------
307+
- name: Cache Cargo
308+
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
309+
with:
310+
workspaces: client-sdk-rust -> target
311+
key: coverage
312+
313+
# ---------- Build environment setup ----------
314+
- name: Set build environment
315+
run: |
316+
LLVM_VERSION=$(llvm-config --version | cut -d. -f1)
317+
echo "LIBCLANG_PATH=/usr/lib/llvm-${LLVM_VERSION}/lib" >> $GITHUB_ENV
318+
GCC_VER=$(gcc -dumpversion | cut -d. -f1)
319+
echo "GCOV_EXECUTABLE=gcov-${GCC_VER}" >> $GITHUB_ENV
320+
321+
# ---------- Configure with upstream preset + coverage flag overrides ----------
322+
- name: Configure (linux-debug-tests preset + coverage flags)
323+
run: |
324+
cmake --preset linux-debug-tests \
325+
-DCMAKE_C_FLAGS="-Wno-deprecated-declarations --coverage" \
326+
-DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations --coverage" \
327+
-DCMAKE_EXE_LINKER_FLAGS="--coverage" \
328+
-DCMAKE_SHARED_LINKER_FLAGS="--coverage"
329+
330+
- name: Build
331+
run: cmake --build build-debug --parallel
332+
333+
# ---------- Run unit tests ----------
334+
- name: Run unit tests
335+
timeout-minutes: 5
336+
run: |
337+
build-debug/bin/livekit_unit_tests \
338+
--gtest_output=xml:build-debug/unit-test-results.xml
339+
340+
# ---------- Generate coverage reports ----------
341+
- name: Generate coverage reports
342+
run: |
343+
mkdir -p coverage-html
344+
gcovr build-debug \
345+
--root . \
346+
--gcov-executable "${GCOV_EXECUTABLE}" \
347+
--gcov-ignore-parse-errors=all \
348+
--filter 'src/' \
349+
--exclude 'src/tests/' \
350+
--exclude '.*\.pb\.' \
351+
--exclude-unreachable-branches \
352+
--exclude-throw-branches \
353+
--cobertura coverage.xml \
354+
--html-details coverage-html/index.html \
355+
--txt coverage-summary.txt
356+
357+
- name: Add coverage summary to job
358+
run: |
359+
{
360+
echo '## Code Coverage Summary'
361+
echo ''
362+
echo '```'
363+
cat coverage-summary.txt
364+
echo '```'
365+
echo ''
366+
echo '*Full HTML report available in the **coverage-report** artifact.*'
367+
} >> "$GITHUB_STEP_SUMMARY"
368+
369+
# ---------- Upload reports ----------
370+
- name: Upload coverage HTML report
371+
if: always()
372+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
373+
with:
374+
name: coverage-report
375+
path: coverage-html/
376+
retention-days: 14
377+
378+
- name: Upload coverage to Codecov
379+
uses: getsentry/codecov-action@03112cc3b486a3397dc8d17a58680008721fc86f # v0.3.7
380+
with:
381+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)