Skip to content

Commit 743377f

Browse files
nficanoARCP Swift SDKclaude
authored
ci: collect + upload coverage to Codecov (#65)
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: ARCP Swift SDK <arcp@example.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e6800b8 commit 743377f

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,40 @@ jobs:
7878
- name: Build
7979
run: swift build --build-tests
8080

81-
- name: Test
82-
run: swift test --skip-build
81+
- name: Test (with code coverage)
82+
run: swift test --skip-build --enable-code-coverage
83+
84+
# swift test --enable-code-coverage produces a profdata file under
85+
# .build/<arch>/debug/codecov/. Export to lcov via llvm-cov so
86+
# Codecov can parse it. Non-blocking so a Codecov outage cannot
87+
# break CI.
88+
- name: Export coverage (lcov)
89+
run: |
90+
binary=$(swift build --show-bin-path)
91+
profdata="$binary/codecov/default.profdata"
92+
xctest=$(find "$binary" -maxdepth 3 -name "*.xctest" -print -quit)
93+
# SwiftPM packages tests inside a .xctest bundle. On macOS the
94+
# executable lives at <bundle>/Contents/MacOS/<name>.
95+
if [[ -d "$xctest/Contents/MacOS" ]]; then
96+
exe=$(find "$xctest/Contents/MacOS" -type f -perm -u+x -print -quit)
97+
else
98+
exe="$xctest"
99+
fi
100+
xcrun llvm-cov export "$exe" \
101+
-instr-profile="$profdata" \
102+
-format=lcov \
103+
-ignore-filename-regex='(\.build|Tests)/' \
104+
> coverage.lcov
105+
shell: bash
106+
107+
- name: Upload coverage to Codecov
108+
# codecov/codecov-action v6.0.1
109+
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
110+
with:
111+
fail_ci_if_error: false
112+
flags: unittests
113+
files: ./coverage.lcov
114+
token: ${{ secrets.CODECOV_TOKEN }}
83115

84116
- name: Upload test artifacts on failure
85117
if: failure()

0 commit comments

Comments
 (0)