Skip to content

ci: collect + upload coverage to Codecov#65

Merged
nficano merged 1 commit into
mainfrom
chore/codecov-upload
May 25, 2026
Merged

ci: collect + upload coverage to Codecov#65
nficano merged 1 commit into
mainfrom
chore/codecov-upload

Conversation

@nficano
Copy link
Copy Markdown
Contributor

@nficano nficano commented May 25, 2026

Summary

  • Add --enable-code-coverage to swift test.
  • Export the .profdata to LCOV via xcrun llvm-cov (only xcrun is available on the macOS runner; SwiftPM tests are bundled inside a .xctest package, hence the executable-resolution dance).
  • Upload coverage.lcov to Codecov.
  • fail_ci_if_error: false so a Codecov outage cannot break CI.

Pre-merge action required

  • Add CODECOV_TOKEN as a repo secret (gh secret set CODECOV_TOKEN --repo agentruntimecontrolprotocol/swift-sdk).
  • Activate the repo at app.codecov.io.

Test plan

  • Merge, confirm coverage uploads on next push to main.
  • Spot-check coverage % in the Codecov dashboard for sanity (large drop would indicate the regex / xctest-resolution went wrong).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Enhanced continuous integration workflow by adding code coverage tracking. Coverage metrics are now generated and uploaded to Codecov for improved visibility into code quality assurance.

Review Change Stack

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

Walkthrough

The 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.

Changes

Code coverage integration in CI

Layer / File(s) Summary
Code coverage collection and reporting
.github/workflows/test.yml
Test execution enables code coverage collection with swift test --enable-code-coverage. Coverage data is exported to coverage.lcov by locating the test executable from the macOS bundle layout and reading the generated .profdata file via xcrun llvm-cov export. The coverage file is uploaded to Codecov using codecov/codecov-action pinned to a specific commit SHA, configured with fail_ci_if_error: false, the unittests flag, and a secret token.

🎯 2 (Simple) | ⏱️ ~15 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'ci: collect + upload coverage to Codecov' clearly and specifically summarizes the main change: adding code coverage collection and upload to Codecov in the CI workflow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/codecov-upload

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/test.yml (1)

88-105: ⚡ Quick win

Consider 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

📥 Commits

Reviewing files that changed from the base of the PR and between e6800b8 and f258dcc.

📒 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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"
fi

Repository: 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.

@nficano nficano merged commit 743377f into main May 25, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant