ci: collect + upload coverage to Codecov#65
Conversation
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) <noreply@anthropic.com>
WalkthroughThe CI test workflow is enhanced to collect and report code coverage. The test step now runs with code coverage enabled, a new step exports coverage metrics to lcov format by locating the built test executable and profiling data, and a final step uploads the coverage report to Codecov using a pinned action version and repository secret for authentication. ChangesCode coverage integration in CI
🎯 2 (Simple) | ⏱️ ~15 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.github/workflows/test.yml (1)
88-105: ⚡ Quick winConsider adding explicit error checks for better debuggability.
The export script will fail if required files aren't found, but the error messages may be unclear. Adding explicit checks would help future maintainers diagnose issues more quickly.
🛡️ Suggested defensive checks
- name: Export coverage (lcov) run: | binary=$(swift build --show-bin-path) profdata="$binary/codecov/default.profdata" + if [[ ! -f "$profdata" ]]; then + echo "Error: profdata not found at $profdata" + exit 1 + fi xctest=$(find "$binary" -maxdepth 3 -name "*.xctest" -print -quit) + if [[ -z "$xctest" ]]; then + echo "Error: No .xctest bundle found in $binary" + exit 1 + fi # SwiftPM packages tests inside a .xctest bundle. On macOS the # executable lives at <bundle>/Contents/MacOS/<name>. if [[ -d "$xctest/Contents/MacOS" ]]; then exe=$(find "$xctest/Contents/MacOS" -type f -perm -u+x -print -quit) else exe="$xctest" fi + if [[ -z "$exe" ]]; then + echo "Error: No executable found in xctest bundle" + exit 1 + fi xcrun llvm-cov export "$exe" \ -instr-profile="$profdata" \ -format=lcov \ -ignore-filename-regex='(\.build|Tests)/' \ > coverage.lcov shell: bash🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.github/workflows/test.yml around lines 88 - 105, Add defensive checks and clear error messages before running llvm-cov: after computing binary=$(swift build --show-bin-path) verify the directory exists and is non-empty; check profdata="$binary/codecov/default.profdata" exists; ensure xctest was found (xctest is non-empty) and that exe (either found under "$xctest/Contents/MacOS" or "$xctest") points to an executable file; if any check fails, print a descriptive message mentioning the failing variable (binary/profdata/xctest/exe) and exit 1 so the subsequent xcrun llvm-cov export step fails fast with a clear error.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/test.yml:
- Line 109: The workflow pins the Codecov action to a SHA that doesn't match the
inline version comment; update the `uses:
codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354` entry so the
SHA and the `# v6.0.1` comment are consistent: either replace the SHA with the
commit that `v6.0.1` resolves to (cddd853df119a48c5be31a973f8cd97e12e35e16) or
change the inline version comment to the tag/SHA you're actually pinning,
ensuring the `uses:` value and the `#` comment match.
---
Nitpick comments:
In @.github/workflows/test.yml:
- Around line 88-105: Add defensive checks and clear error messages before
running llvm-cov: after computing binary=$(swift build --show-bin-path) verify
the directory exists and is non-empty; check
profdata="$binary/codecov/default.profdata" exists; ensure xctest was found
(xctest is non-empty) and that exe (either found under "$xctest/Contents/MacOS"
or "$xctest") points to an executable file; if any check fails, print a
descriptive message mentioning the failing variable (binary/profdata/xctest/exe)
and exit 1 so the subsequent xcrun llvm-cov export step fails fast with a clear
error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6ffe98dd-9732-4a16-9aac-2ced66322cbc
📒 Files selected for processing (1)
.github/workflows/test.yml
|
|
||
| - name: Upload coverage to Codecov | ||
| # codecov/codecov-action v6.0.1 | ||
| uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1 |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Verify codecov-action SHA matches v6.0.1 tag
# Fetch the commit SHA for the v6.0.1 tag
tag_sha=$(gh api repos/codecov/codecov-action/git/ref/tags/v6.0.1 --jq '.object.sha')
echo "v6.0.1 tag SHA: $tag_sha"
# Compare with the pinned SHA in the workflow
pinned_sha="e79a6962e0d4c0c17b229090214935d2e33f8354"
echo "Pinned SHA: $pinned_sha"
if [[ "$tag_sha" == "$pinned_sha" ]]; then
echo "✓ SHA matches v6.0.1"
else
echo "✗ SHA mismatch - please update to the correct SHA for v6.0.1"
fiRepository: agentruntimecontrolprotocol/swift-sdk
Length of output: 252
Fix Codecov action SHA/version mismatch
In .github/workflows/test.yml (line 109), codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1 is incorrect: the v6.0.1 tag resolves to cddd853df119a48c5be31a973f8cd97e12e35e16. Update the pinned SHA and/or the inline version comment to match.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/test.yml at line 109, The workflow pins the Codecov action
to a SHA that doesn't match the inline version comment; update the `uses:
codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354` entry so the
SHA and the `# v6.0.1` comment are consistent: either replace the SHA with the
commit that `v6.0.1` resolves to (cddd853df119a48c5be31a973f8cd97e12e35e16) or
change the inline version comment to the tag/SHA you're actually pinning,
ensuring the `uses:` value and the `#` comment match.
Summary
--enable-code-coveragetoswift test..profdatato LCOV viaxcrun llvm-cov(onlyxcrunis available on the macOS runner; SwiftPM tests are bundled inside a.xctestpackage, hence the executable-resolution dance).coverage.lcovto Codecov.fail_ci_if_error: falseso a Codecov outage cannot break CI.Pre-merge action required
CODECOV_TOKENas a repo secret (gh secret set CODECOV_TOKEN --repo agentruntimecontrolprotocol/swift-sdk).Test plan
main.🤖 Generated with Claude Code
Summary by CodeRabbit