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