Skip to content

Support mixed Python/Rust coverage#17

Merged
leynos merged 5 commits intomainfrom
codex/update-generate-coverage-action-for-python-and-rust
Jun 25, 2025
Merged

Support mixed Python/Rust coverage#17
leynos merged 5 commits intomainfrom
codex/update-generate-coverage-action-for-python-and-rust

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 25, 2025

Summary

  • support mixed Python/Rust projects in generate-coverage action
  • merge cobertura files with uvx merge-cobertura
  • document new behaviour and bump changelog

Testing

  • npm test (fails: could not find package.json)

https://chatgpt.com/codex/tasks/task_e_685beca3efbc83228c330b6019daae9d

Summary by Sourcery

Add mixed Python/Rust coverage support to the Generate coverage action

New Features:

  • Detect and run coverage for mixed Python and Rust projects
  • Merge per-language Cobertura reports using uvx merge-cobertura

Enhancements:

  • Refactor detection step to distinguish rust, python, or mixed modes
  • Dynamically adjust output file names and enforce Cobertura format in mixed mode

Documentation:

  • Update action description, README flowchart, inputs, and CHANGELOG for mixed support

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 25, 2025

Reviewer's Guide

This PR enhances the generate-coverage action to detect and handle mixed Python/Rust repositories: it replaces the strict single-language detection with flag-based logic, adjusts the Rust and Python coverage steps to emit separate reports, introduces a merge step for Cobertura outputs in mixed mode, and updates documentation and the changelog accordingly.

Flow diagram for mixed Python/Rust coverage support

flowchart TD
    A[Start] --> B{Project type?}
    B -- Both present --> C[Set lang=mixed]
    B -- Cargo.toml only --> D[Set lang=rust]
    B -- pyproject.toml only --> E[Set lang=python]
    B -- Neither --> F[Exit with error]
    C --> G{lang}
    D --> G
    E --> G
    G -- rust --> H[Run cargo llvm-cov]
    G -- python --> I[Run slipcover with pytest]
    G -- mixed --> J[Run both & merge]
    H --> K[Set outputs]
    I --> K
    J --> K
    K --> L[End]
Loading

File-Level Changes

Change Details Files
Enhanced detection logic to support mixed projects
  • Introduced has_rust and has_python flags in the detect step
  • Set lang=mixed when both Cargo.toml and pyproject.toml are present
  • Enforced cobertura-only format for mixed projects
  • Updated error handling for missing or unsupported combinations
.github/actions/generate-coverage/action.yml
Adjusted coverage steps for mixed mode
  • Expanded rust and python step conditions to include mixed
  • Added step IDs (rust, python) for clearer output references
  • Parameterized output-path to produce .rust.xml and .python.xml
  • Emitted file outputs for each language step
.github/actions/generate-coverage/action.yml
Added merge step for Cobertura reports in mixed mode
  • Inserted a conditional step that runs only for mixed
  • Used uvx merge-cobertura to combine the two XML reports
  • Redirected merged output to the main output-path
.github/actions/generate-coverage/action.yml
Updated documentation to reflect mixed mode support
  • Modified README description to include mixed coverage
  • Revised flowchart to show mixed branch and merge step
  • Noted cobertura-only requirement for mixed in inputs table
  • Expanded lang output options to include 'mixed'
.github/actions/generate-coverage/README.md
Bumped changelog for new mixed support release
  • Added v1.2.0 entry with support for combined Python/Rust projects
  • Documented use of uvx merge-cobertura for report merging
.github/actions/generate-coverage/CHANGELOG.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 25, 2025

Summary by CodeRabbit

  • New Features
    • Added support for projects containing both Python and Rust code, with automatic detection and merged coverage reporting.
  • Documentation
    • Updated documentation to describe mixed-language support, revised flowcharts, and clarified usage instructions for new features.

Summary by CodeRabbit

  • New Features

    • Added support for projects containing both Rust and Python code, enabling combined coverage reporting and automated merging of Cobertura reports.
  • Documentation

    • Updated documentation to reflect support for mixed Rust and Python projects, revised flowcharts, and clarified input/output requirements for multi-language coverage.
  • Style

    • Improved action descriptions and output naming for clarity in mixed-language scenarios.

Walkthrough

The changes introduce support for projects containing both Python and Rust codebases in the GitHub Action for coverage generation. The action now detects mixed-language projects, runs coverage for both languages, and merges their Cobertura reports. Documentation and workflow descriptions have been updated to reflect these enhancements.

Changes

File(s) Change Summary
.github/actions/generate-coverage/CHANGELOG.md Added changelog entry for v1.2.0 detailing mixed Python/Rust project support and Cobertura merging.
.github/actions/generate-coverage/README.md Updated documentation, flowchart, and input/output descriptions for mixed-language coverage support.
.github/actions/generate-coverage/action.yml Modified action logic to detect mixed projects, run both coverages, and merge Cobertura reports.

Sequence Diagram(s)

sequenceDiagram
    participant Workflow
    participant Action
    participant RustCov
    participant PyCov
    participant UvxMerge

    Workflow->>Action: Start coverage action
    Action->>Action: Detect project language(s)
    alt Rust only
        Action->>RustCov: Run Rust coverage
        RustCov-->>Action: Rust coverage report
        Action->>Workflow: Output Rust coverage
    else Python only
        Action->>PyCov: Run Python coverage
        PyCov-->>Action: Python coverage report
        Action->>Workflow: Output Python coverage
    else Mixed (Rust + Python)
        Action->>RustCov: Run Rust coverage (rust.cobertura.xml)
        RustCov-->>Action: Rust coverage report
        Action->>PyCov: Run Python coverage (python.cobertura.xml)
        PyCov-->>Action: Python coverage report
        Action->>UvxMerge: Merge rust.cobertura.xml + python.cobertura.xml
        UvxMerge-->>Action: Merged cobertura.xml
        Action->>Workflow: Output merged coverage
    end
Loading

Possibly related PRs

Poem

In the warren where languages mix and play,
Rust and Python now both have their say.
Coverage reports, once kept apart,
Merge together, a technical art.
With Cobertura joined, the action hops ahead—
A rabbit’s delight in green and red!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f586348 and 4a155f6.

📒 Files selected for processing (1)
  • .github/actions/generate-coverage/action.yml (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`.github/actions/*/action.yml`: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

.github/actions/*/action.yml: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/action.yml
🔇 Additional comments (9)
.github/actions/generate-coverage/action.yml (9)

2-2: LGTM - Description properly updated for mixed project support.

The description now accurately reflects the action's capability to handle mixed Rust and Python projects, addressing the previous feedback about marketplace listing clarity.


7-7: Excellent addition of type annotations.

Adding explicit type: string annotations to the inputs follows GitHub Actions best practices and improves the action's metadata for better tooling support and documentation.

Also applies to: 16-16, 20-20


39-48: Clean detection logic for mixed projects.

The detection logic properly handles all three scenarios (both, rust-only, python-only) with clear variable naming and appropriate error handling for unsupported project types.


50-59: Proper format validation with shell-based lowercasing.

The implementation correctly addresses the previous issue with mixed GitHub expression and Bash syntax by performing the lowercasing operation within the shell after variable assignment.


61-76: Excellent unified validation using case statement.

The refactored validation logic using a single case statement on "$found/$fmt" is much cleaner and more maintainable than the previous separate if statements. This addresses the previous feedback about unifying validation guards.


92-96: Proper filename handling avoids double extensions.

The implementation correctly inserts the .rust tag before the existing file extension using parameter expansion, preventing issues like coverage.xml.rust.xml and ensuring clean filenames.


135-139: Consistent filename handling for Python outputs.

The Python step uses the same pattern as the Rust step for inserting language tags before file extensions, maintaining consistency and avoiding double-extension issues.


156-167: Robust error handling and cleanup in merge step.

The implementation includes:

  • Proper fail-fast checking for missing coverage files with clear error messages
  • Successful merging of coverage reports using uvx merge-cobertura
  • Cleanup of intermediate files to keep the workspace tidy

This addresses multiple previous feedback points about error handling and workspace cleanliness.


105-107: Clean variable assignment and array usage.

The format variable assignment and array building properly avoids double interpolation issues by using shell variables instead of repeated GitHub expression evaluation.

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch codex/update-generate-coverage-action-for-python-and-rust

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests 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.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@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: 3

🔭 Outside diff range comments (1)
.github/actions/generate-coverage/action.yml (1)

4-19: Explicitly declare input types for stronger schema validation.

features, output-path, and format implicitly default to string.
Adding type: string makes intent clear and prevents future drift.

   features:
     description: Cargo features to enable
     required: false
+    type: string
 …
   output-path:
     description: Output file path
     required: true
+    type: string
 …
   format:
     description: Coverage format
     required: false
+    type: string
     default: cobertura
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fcd3eb6 and ddcb487.

📒 Files selected for processing (3)
  • .github/actions/generate-coverage/CHANGELOG.md (1 hunks)
  • .github/actions/generate-coverage/README.md (2 hunks)
  • .github/actions/generate-coverage/action.yml (5 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
`.github/actions/*/CHANGELOG.md`: Each action must have a CHANGELOG.md tracking SemVer-based changes for that action only.

.github/actions/*/CHANGELOG.md: Each action must have a CHANGELOG.md tracking SemVer-based changes for that action only.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/CHANGELOG.md
`.github/actions/*/action.yml`: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

.github/actions/*/action.yml: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/action.yml
`.github/actions/*/README.md`: Each action must have a README.md containing a on...

.github/actions/*/README.md: Each action must have a README.md containing a one-liner summary, table of inputs (name, type, default, description, required?), table of outputs, usage example with 'uses: ./.github/actions/@', and a release history link to CHANGELOG.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/README.md
🔇 Additional comments (2)
.github/actions/generate-coverage/CHANGELOG.md (1)

3-6: Changelog entry looks good.

Version bump, date stamp, and concise summary meet the repo’s semver-driven CHANGELOG requirements.

.github/actions/generate-coverage/action.yml (1)

74-82: Echoing file twice can confuse consumers.

rust (and python) emit a file output, but the final out step overwrites the composite’s file with the user-supplied output-path.
Down-stream workflows expecting the real artefact may read the wrong value when output-path is overridden in mixed mode (*.rust.xml). Consider:

  • Dropping the file echo from the language-specific steps, or
  • Using a distinct key (e.g. partial-file) in those steps and keeping the merged path for the final file.

Also applies to: 90-93

Comment thread .github/actions/generate-coverage/README.md Outdated
Comment thread .github/actions/generate-coverage/action.yml Outdated
Comment thread .github/actions/generate-coverage/action.yml
Copy link
Copy Markdown
Contributor

@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

🔭 Outside diff range comments (2)
.github/actions/generate-coverage/action.yml (2)

79-98: rust step may fail when output is nested – ensure the directory exists.
Unlike the Python step, the Rust block does not mkdir -p "$(dirname "$out")".
Passing a path such as reports/coverage.xml will cause cargo llvm-cov to error with “No such file or directory”.

       out="${{ inputs.output-path }}"
       if [[ "${{ steps.detect.outputs.lang }}" == 'mixed' ]]; then
         out="${{ inputs.output-path }}.rust.xml"
       fi
+      mkdir -p "$(dirname "$out")"

50-56: Accept format names case-insensitively to reduce user friction.
Users occasionally pass Cobertura or LCOV. Normalising to lowercase before validation avoids surprising failures.

-        case "${{ inputs.format }}" in
+        fmt="${{ inputs.format,, }}"   # bash lowercase
+        case "$fmt" in

(and replace subsequent ${{ inputs.format }} references with $fmt)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ddcb487 and 764ab4b.

📒 Files selected for processing (2)
  • .github/actions/generate-coverage/README.md (2 hunks)
  • .github/actions/generate-coverage/action.yml (6 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`.github/actions/*/README.md`: Each action must have a README.md containing a on...

.github/actions/*/README.md: Each action must have a README.md containing a one-liner summary, table of inputs (name, type, default, description, required?), table of outputs, usage example with 'uses: ./.github/actions/@', and a release history link to CHANGELOG.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/README.md
`.github/actions/*/action.yml`: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

.github/actions/*/action.yml: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/action.yml
🔇 Additional comments (1)
.github/actions/generate-coverage/README.md (1)

3-8: Opening sentence now clearly covers mixed projects – looks good.
The wording fully resolves the previous feedback and accurately reflects the new capability.

Comment thread .github/actions/generate-coverage/action.yml Outdated
Copy link
Copy Markdown
Contributor

@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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 764ab4b and 972e875.

📒 Files selected for processing (2)
  • .github/actions/generate-coverage/README.md (2 hunks)
  • .github/actions/generate-coverage/action.yml (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`.github/actions/*/README.md`: Each action must have a README.md containing a on...

.github/actions/*/README.md: Each action must have a README.md containing a one-liner summary, table of inputs (name, type, default, description, required?), table of outputs, usage example with 'uses: ./.github/actions/@', and a release history link to CHANGELOG.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/README.md
`.github/actions/*/action.yml`: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

.github/actions/*/action.yml: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/action.yml
🔇 Additional comments (5)
.github/actions/generate-coverage/README.md (4)

3-8: Opening sentence is clear – good update.

The new wording explicitly mentions mixed projects and resolves the past review comment.
No further action required.


15-28: Mermaid branch labels align with new logic.

The flowchart now visualises the mixed branch correctly; naming is consistent with the code (lang=mixed).
Looks good.


40-41: Foot-note clarifies format limitations – nice touch.

The asterisk note prevents mis-configuration for mixed projects.
All good.


48-48: Outputs table updated – LGTM.

Including mixed in the lang output keeps docs and action contract in sync.

.github/actions/generate-coverage/action.yml (1)

145-155: Nice fail-fast guard before merging.

The explicit file-existence check addresses the earlier review concern – well done.

Comment thread .github/actions/generate-coverage/action.yml Outdated
Comment thread .github/actions/generate-coverage/action.yml
Copy link
Copy Markdown
Contributor

@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: 5

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 972e875 and f586348.

📒 Files selected for processing (1)
  • .github/actions/generate-coverage/action.yml (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`.github/actions/*/action.yml`: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

.github/actions/*/action.yml: Each action must have an action.yml file containing all inputs and outputs, with required ones clearly marked.

📄 Source: CodeRabbit Inference Engine (AGENTS.md)

List of files the instruction was applied to:

  • .github/actions/generate-coverage/action.yml
🔇 Additional comments (5)
.github/actions/generate-coverage/action.yml (5)

39-45: Robust mixed-project detection – looks good

Cleanly distinguishes rust, python, and mixed projects instead of erroring out. This unblocks mixed-language repositories without complicating the logic.


50-58: Lower-case normalisation bug resolved

Moving the ,, expansion into the shell eliminates the earlier syntax issue—nice catch.


74-78: Consistent lang mapping

Mapping both → mixed keeps external outputs clean.


132-147: Slipcover invocation looks correct

Branch coverage and XML generation wired appropriately.


161-163: Final outputs wired correctly

The composite step exposes the merged file path and normalised format as expected.

Comment thread .github/actions/generate-coverage/action.yml
Comment thread .github/actions/generate-coverage/action.yml Outdated
Comment thread .github/actions/generate-coverage/action.yml
Comment thread .github/actions/generate-coverage/action.yml
Comment thread .github/actions/generate-coverage/action.yml
@leynos leynos merged commit 4471928 into main Jun 25, 2025
1 check passed
@leynos leynos deleted the codex/update-generate-coverage-action-for-python-and-rust branch June 25, 2025 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant