Skip to content

[ECO-5252] Generate a code coverage report in CI#238

Merged
lawrence-forooghian merged 1 commit intomainfrom
code-coverage
Mar 17, 2025
Merged

[ECO-5252] Generate a code coverage report in CI#238
lawrence-forooghian merged 1 commit intomainfrom
code-coverage

Conversation

@lawrence-forooghian
Copy link
Copy Markdown
Collaborator

@lawrence-forooghian lawrence-forooghian commented Mar 13, 2025

Resolves #240.

Example of report (see comment in workflow YAML for some things that could be improved here):

image

Summary by CodeRabbit

  • New Features
    • Integrated an automated process that generates detailed code coverage reports, complete with a comprehensive Markdown summary of testing results.
    • Introduced a dedicated command for generating coverage data, offering more flexibility with report options and test plan details.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 13, 2025

Walkthrough

This pull request adds code coverage generation capabilities to the CI pipeline. A new job called code-coverage is introduced in the GitHub Actions workflow to run on macOS 15 and generate reports, which includes steps for checking out the code, setting up Xcode, and generating a Markdown report. In parallel, a new GenerateCodeCoverage struct is added to the BuildTool to support the generation of code coverage reports, and the XcodeRunner was updated to support additional parameters for test plans and bundle paths.

Changes

Files Summary of Changes
.github/workflows/check.yaml Added a new code-coverage job that checks out the repository, sets up Xcode, runs code coverage generation, and creates a Markdown report. Integrated this job with the overall workflow by adding it as a dependency to all-checks-completed.
Sources/BuildTool/BuildTool.swift Added a new GenerateCodeCoverage struct conforming to AsyncParsableCommand, with an option for specifying the result bundle path. The new subcommand is added to the BuildTool configuration.
Sources/BuildTool/XcodeRunner.swift Updated runXcodebuild to accept new optional parameters (testPlan and resultBundlePath) and conditionally include them in the command arguments.

Sequence Diagram(s)

sequenceDiagram
  participant GitHubActions as GitHub Actions
  participant BuildTool as BuildTool CLI
  participant XcodeRunner as Xcode Runner
  participant ReportGen as xcresulttool Action

  GitHubActions->>GitHubActions: Trigger code-coverage job (after generate-matrices)
  GitHubActions->>BuildTool: Execute "swift run BuildTool generate-code-coverage --result-bundle-path CodeCoverage.xcresult"
  BuildTool->>XcodeRunner: Call runXcodebuild(action: "test", scheme: "AblyChat", destination: macOS, testPlan: <value>, resultBundlePath: CodeCoverage.xcresult)
  XcodeRunner-->>BuildTool: Return test results and coverage data
  BuildTool->>GitHubActions: Pass coverage data to workflow
  GitHubActions->>ReportGen: Generate Markdown coverage report (runs on both success and failure)
Loading

Assessment against linked issues

Objective Addressed Explanation
Calculate code coverage information in CI (#240, ECO-5252)

Possibly related PRs

Poem

I’m a joyful rabbit,
Hoping through the code I leap,
Code coverage now blossoms,
In workflows, promises we keep.
With each test and report,
I smile in ASCII cheer—
For every change, a boundless, bouncing year!

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot temporarily deployed to staging/pull/238/AblyChat March 13, 2025 20:09 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/238/AblyChat March 13, 2025 20:12 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/238/AblyChat March 13, 2025 20:25 Inactive
@lawrence-forooghian lawrence-forooghian changed the title Code coverage [ECO-5252] Generate a code coverage report in CI Mar 17, 2025
@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review March 17, 2025 12:50
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: 0

🧹 Nitpick comments (3)
.github/workflows/check.yaml (1)

173-174:

Details

❓ Verification inconclusive

Consider setting additional configuration options

The xcresulttool action appears to support additional configurations that might be useful, such as filtering out specific targets from the coverage report.


🏁 Script executed:

#!/bin/bash
# Display available configuration options for xcresulttool
curl -s https://raw.githubusercontent.com/slidoapp/xcresulttool/v3.1.0/action.yml | grep -A 2 "  [a-z]"

Length of output: 836


Action Required: Review Additional xcresulttool Configuration Options

The current configuration in your workflow:

          show-passed-tests: false
        if: success() || failure()

is functionally acceptable. However, our verification of the xcresulttool action (v3.1.0) confirms it supports several configurable options beyond show-passed-tests, including:

  • show-code-coverage (default: true)
  • upload-bundles (default: always)
  • Other parameters such as path, token, and title

While there isn't a direct configuration key for filtering out specific targets from the coverage report, these additional options allow you to further customize the output and behavior of the action.

Recommendation:

  • Review if adjusting options like show-code-coverage or upload-bundles can help tailor the test result reporting to your needs.

  • Use the command below to inspect the available configuration settings in the xcresulttool action if needed:

    curl -s https://raw.githubusercontent.com/slidoapp/xcresulttool/v3.1.0/action.yml | grep -A 2 "  [a-z]"

Please verify if incorporating these adjustments improves clarity or filtering in your results configuration.

Sources/BuildTool/BuildTool.swift (2)

86-87: Consider making platform configurable

The platform is currently hardcoded to macOS. Consider making it an optional parameter like in other commands, in case there's a need to generate coverage for other platforms in the future.

-    mutating func run() async throws {
-        let platform = Platform.macOS
-        let destinationSpecifier = try await platform.resolve()
+    @Option(help: "Platform to run tests on for code coverage.", default: Platform.macOS)
+    var platform: Platform
+
+    mutating func run() async throws {
+        let destinationSpecifier = try await platform.resolve()

94-94: Consider making test plan configurable

The test plan is currently hardcoded as "UnitTests". Consider making it an optional parameter like resultBundlePath, which would provide more flexibility if additional test plans are added in the future.

     @Option(help: "Pathname of where to output the .xcresult bundle.")
     var resultBundlePath: String
 
+    @Option(help: "The test plan to use for code coverage.", default: "UnitTests")
+    var testPlan: String
+
     mutating func run() async throws {
         let platform = Platform.macOS
         let destinationSpecifier = try await platform.resolve()
         let scheme = "AblyChat"
 
         try await XcodeRunner.runXcodebuild(
             action: "test",
             scheme: scheme,
             destination: destinationSpecifier,
-            testPlan: "UnitTests",
+            testPlan: testPlan,
             resultBundlePath: resultBundlePath
         )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc690c3 and 04d8565.

📒 Files selected for processing (3)
  • .github/workflows/check.yaml (2 hunks)
  • Sources/BuildTool/BuildTool.swift (2 hunks)
  • Sources/BuildTool/XcodeRunner.swift (2 hunks)
🔇 Additional comments (7)
.github/workflows/check.yaml (3)

141-174: Well-structured job for code coverage generation

The new code-coverage job is well-structured and follows the pattern of other jobs in the workflow. It correctly checks out the code, sets up Xcode, and generates the coverage report using both the BuildTool command and the xcresulttool action.


157-175: Great documentation of potential improvements

Your comments clearly document the current limitations and potential areas for improvement in the code coverage reporting, which is helpful for future development.


285-285: Correctly includes the new job in the all-checks-completed dependencies

The code-coverage job is properly added to the dependencies of the all-checks-completed job, ensuring it's included in the required checks.

Sources/BuildTool/XcodeRunner.swift (2)

5-5: Function signature updated with backward-compatible parameters

The addition of optional parameters with default values ensures backward compatibility with existing code.


19-25: Clean implementation for adding conditional arguments

The implementation correctly appends the new parameters to the xcodebuild arguments array only when they are provided.

Sources/BuildTool/BuildTool.swift (2)

19-19: Correctly adding new command to BuildTool configuration

The GenerateCodeCoverage command is properly added to the subcommands list, making it available as a CLI option.


75-98: Well-structured implementation of code coverage command

The GenerateCodeCoverage struct follows the same pattern as other commands in this file and clearly implements the necessary functionality.

Comment thread Sources/BuildTool/BuildTool.swift
Copy link
Copy Markdown
Collaborator

@maratal maratal left a comment

Choose a reason for hiding this comment

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

LGTM

@lawrence-forooghian lawrence-forooghian merged commit 507ddaf into main Mar 17, 2025
19 checks passed
@lawrence-forooghian lawrence-forooghian deleted the code-coverage branch March 17, 2025 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Calculate code coverage information in CI

2 participants