Skip to content

Add Python support to coverage action#14

Merged
leynos merged 6 commits intomainfrom
codex/update-coverage-action-for-rust-and-python-tests
Jun 24, 2025
Merged

Add Python support to coverage action#14
leynos merged 6 commits intomainfrom
codex/update-coverage-action-for-rust-and-python-tests

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 24, 2025

Summary

  • expand generate-coverage to detect Cargo or Python projects
  • run slipcover for Python test coverage
  • expose coverage file path and format
  • document behaviour and release notes for the action

Testing

  • git status --short

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

Summary by Sourcery

Expand the generate-coverage action to support Python projects alongside Rust by detecting project type, installing dependencies, validating formats, running appropriate coverage tools, and exposing new outputs, with updated documentation and changelog

New Features:

  • Detect project language (Rust or Python) and run coverage with either cargo llvm-cov or slipcover plus pytest
  • Expose coverage file path, format, and detected language as action outputs

Enhancements:

  • Change default coverage format to cobertura and validate format compatibility per language
  • Fail fast when both Cargo.toml and pyproject.toml are detected

Documentation:

  • Add README with usage details, flowchart, inputs/outputs, and example
  • Add CHANGELOG documenting new Python support, outputs, and installation enhancements

Summary by CodeRabbit

  • New Features

    • Added support for code coverage analysis in both Rust and Python projects via a GitHub Action.
    • The action now automatically detects the project language and runs the appropriate coverage tool.
    • Outputs for the coverage file path and format are now provided.
  • Documentation

    • Introduced a comprehensive README detailing usage, inputs, outputs, and example configurations.
    • Added a changelog file documenting version history and new features.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 24, 2025

Reviewer's Guide

This PR extends the Generate coverage GitHub Action to detect Rust or Python projects, validate formats, dispatch the correct coverage toolchain, expose new outputs, and update documentation.

Class diagram for coverage action outputs and detection logic

classDiagram
    class GenerateCoverageAction {
      +features: string
      +with-default-features: boolean
      +output-path: string
      +format: string
      +file: string (output)
      +format: string (output)
      +lang: string (output)
      +detectProjectType()
      +validateFormat()
      +runRustCoverage()
      +runPythonCoverage()
    }
    GenerateCoverageAction <|-- RustCoverage
    GenerateCoverageAction <|-- PythonCoverage
    class RustCoverage {
      +runCargoLlvmCov()
    }
    class PythonCoverage {
      +installSlipcoverAndPytest()
      +runSlipcoverWithPytest()
    }
Loading

Flow diagram for project type detection and coverage execution

flowchart TD
    A[Start] --> B{Project type?}
    B -- Cargo.toml present --> C[Set lang=rust]
    B -- pyproject.toml present --> D[Set lang=python]
    B -- Neither present --> E[Exit with error]
    C --> F{lang}
    D --> F
    F -- rust --> G[Run cargo llvm-cov]
    F -- python --> H[Run slipcover with pytest]
    G --> I[Set outputs: file, format]
    H --> I
    I --> J[End]
Loading

File-Level Changes

Change Details Files
Add project language detection and validation logic
  • Introduce a detect step to set lang based on presence of Cargo.toml or pyproject.toml
  • Fail fast when both or neither config files are found
  • Validate format input compatibility per detected language
.github/actions/generate-coverage/action.yml
Define and expose new action inputs and outputs
  • Change default format to cobertura
  • Add with-default-features as a boolean type
  • Declare file, format, and lang outputs in the action metadata
.github/actions/generate-coverage/action.yml
Integrate Python coverage workflow with slipcover and pytest
  • Install Python via astral-sh/setup-uv and cache dependencies
  • Install slipcover and pytest before running tests
  • Run coverage commands for cobertura and coveragepy formats
  • Emit coverage file to the specified output path
.github/actions/generate-coverage/action.yml
Add documentation and changelog entries for Python support
  • Create a README with usage, inputs, outputs, flowchart, and examples
  • Add CHANGELOG.md entries for v1.1.0 and v1.1.1 outlining new features
.github/actions/generate-coverage/README.md
.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 24, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce documentation and enhancements to the generate-coverage GitHub Action, expanding its support from Rust-only to both Rust and Python projects. New outputs (file and format) are added, and the action now detects the project language, running the appropriate coverage tool and format based on configuration and project files.

Changes

File(s) Summary
.github/actions/generate-coverage/CHANGELOG.md Added changelog documenting initial Rust support and new Python support with outputs for file and format.
.github/actions/generate-coverage/README.md Added README detailing action usage, inputs, outputs, and example for both Rust and Python projects.
.github/actions/generate-coverage/action.yml Updated action: language detection, conditional steps for Rust/Python, new outputs for file and format.

Poem

In the warren of code, a new path appears,
Coverage for Rust and Python, the rabbit cheers!
With outputs now clearer, and docs shining bright,
Our action detects, then hops left or right.
Reports in new formats, all bundled with care—
A leap for the codebase, with coverage to spare!
🐇✨

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

🪧 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 - here's some feedback:

  • The Python branch assumes slipcover and pytest are available—consider adding a setup step (e.g. pip install slipcover pytest) or documenting that prerequisite.
  • The default format is “lcov”, which isn’t supported for Python; either adjust the default based on detected language or validate/override the default when running Python.
  • If a repo contains both Cargo.toml and pyproject.toml, the current detection will always pick Rust—consider allowing an explicit override or a consistent precedence rule.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The Python branch assumes slipcover and pytest are available—consider adding a setup step (e.g. pip install slipcover pytest) or documenting that prerequisite.
- The default format is “lcov”, which isn’t supported for Python; either adjust the default based on detected language or validate/override the default when running Python.
- If a repo contains both Cargo.toml and pyproject.toml, the current detection will always pick Rust—consider allowing an explicit override or a consistent precedence rule.

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

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

14-17: Global default lcov will break the Python pathway.

Same problem as in the README: a Python-only repo with no explicit format input fails at runtime because the Python case does not accept lcov.

Quick fix (minimal diff):

-  format:
-    description: Coverage format
-    required: false
-    default: lcov
+  format:
+    description: Coverage format
+    required: false
+    # Default resolved dynamically; see `detect` step.

Then, just after language detection, set a per-lang default:

if [ -z "${{ inputs.format }}" ]; then
  if [ "$lang" = rust ]; then format=lcov
  else format=cobertura      # python
  fi
else
  format="${{ inputs.format }}"
fi

Remember to export format so subsequent steps and the final output pick it up.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4373b10 and d79520f.

📒 Files selected for processing (3)
  • .github/actions/generate-coverage/CHANGELOG.md (1 hunks)
  • .github/actions/generate-coverage/README.md (1 hunks)
  • .github/actions/generate-coverage/action.yml (3 hunks)

Comment thread .github/actions/generate-coverage/CHANGELOG.md Outdated
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
Comment on lines +62 to +82
run: |
set -euo pipefail
case "${{ inputs.format }}" in
cobertura)
python -m slipcover \
--branch \
--xml \
--out "${{ inputs.output-path }}" \
-m pytest -v
;;
coveragepy)
python -m slipcover \
--branch \
-m pytest -v
mv .coverage "${{ inputs.output-path }}"
;;
*)
echo "Unsupported format: ${{ inputs.format }}" >&2
exit 1
;;
esac
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Create output directory & handle slipcover CLI flags.

  1. mv .coverage "${{ inputs.output-path }}" will fail if the target directory does not yet exist (e.g. reports/coverage/.coverage).
  2. Slipcover’s CLI flag is --xml OUTPUT (no --out) in current releases―the command may error.
-            python -m slipcover \
-              --branch \
-              --xml \
-              --out "${{ inputs.output-path }}" \
-              -m pytest -v
+            mkdir -p "$(dirname "${{ inputs.output-path }}")"
+            python -m slipcover \
+              --branch \
+              --xml "${{ inputs.output-path }}" \
+              -m pytest -v

Apply the same mkdir -p guard before the mv in the coveragepy branch.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In .github/actions/generate-coverage/action.yml around lines 62 to 82, the
script moves the .coverage file to the output path without ensuring the target
directory exists, which can cause failure if the directory is missing. Also, the
slipcover CLI uses the --xml flag with an output argument, not --out. Fix this
by adding a mkdir -p command before the mv command in the coveragepy case to
create the output directory if it doesn't exist, and update the slipcover
command in the cobertura case to use --xml with the output path argument instead
of --out.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 24, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 24, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

♻️ Duplicate comments (4)
.github/actions/generate-coverage/CHANGELOG.md (1)

3-12: Add release dates for traceability
The version headings still omit release dates, which was pointed out earlier. Please include at least YYYY-MM-DD next to each version so downstream consumers can map features to a concrete release.

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

96-100: Expose detected language as an output
Downstream jobs cannot branch on lang without re-running detection. Export it together with file and format.

 echo "format=${{ inputs.format }}" >> "$GITHUB_OUTPUT"
+echo "lang=${{ steps.detect.outputs.lang }}" >> "$GITHUB_OUTPUT"

76-83: Incorrect slipcover flags – will exit with error
slipcover expects --xml <FILE>; passing a bare --xml plus a separate --out is invalid in current releases. Combine the flag and remove --out; also pre-create the directory to avoid path errors.

-            python -m slipcover \
-              --branch \
-              --xml \
-              --out "${{ inputs.output-path }}" \
-              -m pytest -v
+            mkdir -p "$(dirname "${{ inputs.output-path }}")"
+            python -m slipcover \
+              --branch \
+              --xml "${{ inputs.output-path }}" \
+              -m pytest -v

85-89: mv will fail when target directory is missing
Add a mkdir -p guard before moving .coverage.

-            mv .coverage "${{ inputs.output-path }}"
+            mkdir -p "$(dirname "${{ inputs.output-path }}")"
+            mv .coverage "${{ inputs.output-path }}"
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d79520f and 8d8314f.

📒 Files selected for processing (3)
  • .github/actions/generate-coverage/CHANGELOG.md (1 hunks)
  • .github/actions/generate-coverage/README.md (1 hunks)
  • .github/actions/generate-coverage/action.yml (3 hunks)
🧰 Additional context used
🪛 LanguageTool
.github/actions/generate-coverage/CHANGELOG.md

[uncategorized] ~6-~6: A determiner appears to be missing. Consider inserting it.
Context: ...- Expose file and format outputs. - Default coverage format changed to cobertura....

(AI_EN_LECTOR_MISSING_DETERMINER)

.github/actions/generate-coverage/README.md

[uncategorized] ~7-~7: Possible missing comma found.
Context: ... tests. If both configuration files are found the action fails. ## Flow ```mermaid ...

(AI_HYDRA_LEO_MISSING_COMMA)

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

31-40: Good: fail fast when both manifests are present
The explicit error improves determinism in mono-repos.

Comment thread .github/actions/generate-coverage/CHANGELOG.md Outdated
Comment thread .github/actions/generate-coverage/README.md
Comment thread .github/actions/generate-coverage/README.md
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 24, 2025

@coderabbitai review

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 24, 2025

@sourcery-ai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 24, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 - here's some feedback:

  • Pin slipcover and pytest to specific versions in the install step to ensure reproducible coverage runs.
  • Add an actions/cache step to cache Python dependencies (slipcover, pytest) and speed up workflow execution.
  • Consider centralizing the coverage format validation logic before language-specific steps to reduce duplication in the bash scripts.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Pin slipcover and pytest to specific versions in the install step to ensure reproducible coverage runs.
- Add an actions/cache step to cache Python dependencies (slipcover, pytest) and speed up workflow execution.
- Consider centralizing the coverage format validation logic before language-specific steps to reduce duplication in the bash scripts.

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: 4

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

7-10: Declare boolean input type for with-default-features

Explicitly marking the input as boolean aids validation and editor intellisense, and avoids accidental string comparisons.

   with-default-features:
     description: Enable default features
     required: false
+    type: boolean
     default: true
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d8314f and 8064114.

📒 Files selected for processing (3)
  • .github/actions/generate-coverage/CHANGELOG.md (1 hunks)
  • .github/actions/generate-coverage/README.md (1 hunks)
  • .github/actions/generate-coverage/action.yml (3 hunks)
🧰 Additional context used
🪛 LanguageTool
.github/actions/generate-coverage/CHANGELOG.md

[uncategorized] ~6-~6: A determiner appears to be missing. Consider inserting it.
Context: ...- Expose file and format outputs. - Default coverage format changed to cobertura....

(AI_EN_LECTOR_MISSING_DETERMINER)

🪛 markdownlint-cli2 (0.17.2)
.github/actions/generate-coverage/CHANGELOG.md

3-3: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


4-4: Lists should be surrounded by blank lines
null

(MD032, blanks-around-lists)


9-9: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


10-10: Lists should be surrounded by blank lines
null

(MD032, blanks-around-lists)


13-13: Headings should be surrounded by blank lines
Expected: 1; Actual: 0; Below

(MD022, blanks-around-headings)


14-14: Lists should be surrounded by blank lines
null

(MD032, blanks-around-lists)

Comment thread .github/actions/generate-coverage/CHANGELOG.md
Comment thread .github/actions/generate-coverage/README.md Outdated
Comment thread .github/actions/generate-coverage/README.md
Comment thread .github/actions/generate-coverage/action.yml
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 24, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 24, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jun 24, 2025

@sourcery-ai review

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 - here's some feedback:

  • Consider using the official setup-python action instead of setup-uv to provision the Python environment for broader compatibility.
  • Cache pip’s package cache (e.g. ~/.cache/pip) rather than ~/.cache/uv so slipcover/pytest installations can reuse wheels and install faster.
  • You could merge the detect and validate steps into a single script block to reduce duplication and simplify the workflow logic.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using the official setup-python action instead of setup-uv to provision the Python environment for broader compatibility.
- Cache pip’s package cache (e.g. ~/.cache/pip) rather than ~/.cache/uv so slipcover/pytest installations can reuse wheels and install faster.
- You could merge the detect and validate steps into a single script block to reduce duplication and simplify the workflow logic.

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.

@leynos leynos merged commit aa19e61 into main Jun 24, 2025
1 check passed
@leynos leynos deleted the codex/update-coverage-action-for-rust-and-python-tests branch June 24, 2025 16:38
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