From f258dcc4c0ee132f2bcaeae3588be98e8f16011a Mon Sep 17 00:00:00 2001 From: ARCP Swift SDK Date: Sun, 24 May 2026 21:25:00 -0400 Subject: [PATCH] ci: collect + upload coverage to Codecov Enable `--enable-code-coverage` on `swift test`, export the resulting profdata to lcov via `xcrun llvm-cov`, and upload to Codecov non-blockingly. Ignore-filename-regex strips out .build/ and Tests/ from the report. Requires CODECOV_TOKEN to be set as a repo secret. Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c50b0a8..a0fe9f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -78,8 +78,40 @@ jobs: - name: Build run: swift build --build-tests - - name: Test - run: swift test --skip-build + - name: Test (with code coverage) + run: swift test --skip-build --enable-code-coverage + + # swift test --enable-code-coverage produces a profdata file under + # .build//debug/codecov/. Export to lcov via llvm-cov so + # Codecov can parse it. Non-blocking so a Codecov outage cannot + # break CI. + - name: Export coverage (lcov) + run: | + binary=$(swift build --show-bin-path) + profdata="$binary/codecov/default.profdata" + xctest=$(find "$binary" -maxdepth 3 -name "*.xctest" -print -quit) + # SwiftPM packages tests inside a .xctest bundle. On macOS the + # executable lives at /Contents/MacOS/. + if [[ -d "$xctest/Contents/MacOS" ]]; then + exe=$(find "$xctest/Contents/MacOS" -type f -perm -u+x -print -quit) + else + exe="$xctest" + fi + xcrun llvm-cov export "$exe" \ + -instr-profile="$profdata" \ + -format=lcov \ + -ignore-filename-regex='(\.build|Tests)/' \ + > coverage.lcov + shell: bash + + - name: Upload coverage to Codecov + # codecov/codecov-action v6.0.1 + uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1 + with: + fail_ci_if_error: false + flags: unittests + files: ./coverage.lcov + token: ${{ secrets.CODECOV_TOKEN }} - name: Upload test artifacts on failure if: failure()