From fd11f489403340647bf385f373d579752a06a427 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 1 Aug 2026 23:05:53 +0000 Subject: [PATCH] Add Codecov code coverage badge and CI integration Enable code coverage in the CI test run, export the results as an lcov report scoped to the library sources (test files, the Demo app, and dependencies are filtered out), and upload it to Codecov. Add a codecov.yml as a second line of defence for the ignore paths and add a coverage badge to the README next to the CI badge. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01HBDhen1gvude7r9Yv4FPzP --- .github/workflows/ci.yml | 26 +++++++++++++++++++++++++- README.md | 2 +- codecov.yml | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 codecov.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8875e54..3ef28f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,31 @@ jobs: run: swift build - name: Test - run: swift test + run: swift test --enable-code-coverage + + # Export coverage as lcov, restricted to library sources. The + # -ignore-filename-regex drops test files, the Demo app, and all + # dependency/build-artifact code so the badge reflects library coverage + # only. Paths are absolute in llvm-cov output, so these fragments match + # anywhere in the checkout. + - name: Export code coverage + run: | + BIN_PATH="$(swift build --show-bin-path)" + XCTEST="$(find "${BIN_PATH}" -maxdepth 1 -name '*.xctest' | head -1)" + COV_BIN="${XCTEST}/Contents/MacOS/$(basename "${XCTEST}" .xctest)" + xcrun llvm-cov export \ + -format=lcov \ + -instr-profile "${BIN_PATH}/codecov/default.profdata" \ + "${COV_BIN}" \ + -ignore-filename-regex='(\.build|Tests|Demo)/' \ + > coverage.lcov + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + files: coverage.lcov + fail_ci_if_error: false + token: ${{ secrets.CODECOV_TOKEN }} docc: name: DocC catalog diff --git a/README.md b/README.md index 1247ab2..a84a18e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReliaBLE -[![CI](https://github.com/Five3Apps/ReliaBLE/actions/workflows/ci.yml/badge.svg)](https://github.com/Five3Apps/ReliaBLE/actions/workflows/ci.yml) +[![CI](https://github.com/Five3Apps/ReliaBLE/actions/workflows/ci.yml/badge.svg)](https://github.com/Five3Apps/ReliaBLE/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/Five3Apps/ReliaBLE/branch/master/graph/badge.svg)](https://codecov.io/gh/Five3Apps/ReliaBLE) A reliable, modern, and easy-to-use Swift package for apps that talk to Bluetooth Low Energy (BLE) peripherals. diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..4abbd06 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,25 @@ +# Codecov configuration for ReliaBLE. +# +# Coverage is measured for the library sources only. The CI workflow already +# filters test files, the Demo app, and dependencies out of the uploaded lcov +# report via llvm-cov's -ignore-filename-regex; the ignore list below is a +# second line of defence so those paths never count toward coverage even if the +# export filter changes. +coverage: + status: + project: + default: + target: auto + threshold: 1% + patch: + default: + target: auto + +ignore: + - "Tests" + - "Demo" + - "**/.build/**" + +comment: + layout: "reach, diff, files" + require_changes: true