Skip to content

Log coverage info in generate-coverage#46

Merged
leynos merged 4 commits intomainfrom
codex/log-current-and-previous-coverage-percentage
Jul 31, 2025
Merged

Log coverage info in generate-coverage#46
leynos merged 4 commits intomainfrom
codex/log-current-and-previous-coverage-percentage

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 28, 2025

Summary

  • print current coverage to the logs
  • show previous coverage when available
  • document the new logging behaviour

Testing

  • make test
  • make lint

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

Summary by Sourcery

Log coverage metrics during the generate-coverage action by printing the current percentage and, when a baseline file is available, the previous percentage. Extend the action inputs and scripts to support a baseline file for ratcheting and update documentation accordingly.

New Features:

  • Log the current coverage percentage after each run in both Python and Rust scripts
  • Display the previous coverage percentage when a baseline file is provided

Enhancements:

  • Add baseline-python-file and baseline-rust-file inputs to the GitHub Action and pass them as environment variables to the coverage scripts

Documentation:

  • Update CHANGELOG.md and README.md to document the new logging behavior

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 28, 2025

Reviewer's Guide

This PR adds logging of current and previous coverage percentages across both Python and Rust scripts in the generate-coverage action, exposes new baseline file inputs in the action metadata, and updates documentation to reflect the new behavior.

Class diagram for updated Python coverage script

classDiagram
    class run_python {
        +main(output_path, lang, fmt, github_output, baseline_file)
        +read_previous(baseline)
    }
    run_python : +main()
    run_python : +read_previous()
Loading

Class diagram for updated Rust coverage script

classDiagram
    class run_rust {
        +main(output_path, features, with_default_features, lang, fmt, github_output, baseline_file)
        +read_previous(baseline)
    }
    run_rust : +main()
    run_rust : +read_previous()
Loading

File-Level Changes

Change Details Files
Add baseline handling and logging in Python coverage script
  • Introduce BASELINE_PYTHON_FILE option
  • Implement read_previous() to read baseline percentage
  • Echo current and previous coverage to logs
.github/actions/generate-coverage/scripts/run_python.py
Add baseline handling and logging in Rust coverage script
  • Introduce BASELINE_RUST_FILE option
  • Implement read_previous() to read baseline percentage
  • Echo current and previous coverage to logs
.github/actions/generate-coverage/scripts/run_rust.py
Expose baseline file inputs in action metadata
  • Add BASELINE_PYTHON_FILE and BASELINE_RUST_FILE to action.yml environment mapping
.github/actions/generate-coverage/action.yml
Document new logging behavior
  • Update README to describe current and previous coverage output
  • Add entry in CHANGELOG for v1.3.4
.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 Jul 28, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 57 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8fd4663 and dd52380.

📒 Files selected for processing (1)
  • .github/actions/generate-coverage/scripts/run_rust.py (5 hunks)

Summary by CodeRabbit

  • New Features

    • The coverage reporting now logs the current coverage percentage after each run.
    • If ratcheting is enabled and a baseline exists, the previous coverage percentage is also displayed.
  • Documentation

    • Updated documentation to clarify logging behaviour for current and previous coverage percentages.
  • Chores

    • Introduced new environment variables to pass baseline coverage file paths to scripts.

Walkthrough

Update the GitHub Action generate-coverage to log the current coverage percentage after each run. When ratcheting is enabled and a baseline exists, also log the previous coverage percentage. Adjust documentation and scripts to support baseline file handling via environment variables for both Python and Rust coverage runs. Extract baseline reading logic into a shared utility module with improved error handling.

Changes

Cohort / File(s) Change Summary
Changelog and Documentation
.github/actions/generate-coverage/CHANGELOG.md, .github/actions/generate-coverage/README.md
Add documentation and changelog entries describing new logging of current and previous coverage percentages.
Action Workflow
.github/actions/generate-coverage/action.yml
Pass BASELINE_RUST_FILE and BASELINE_PYTHON_FILE as environment variables to respective coverage scripts.
Shared Utility Module
.github/actions/generate-coverage/scripts/shared_utils.py
Introduce helper function read_previous_coverage to read and parse baseline coverage files with improved error handling.
Python Coverage Script
.github/actions/generate-coverage/scripts/run_python.py
Use shared helper to read and log baseline coverage; update function signature and add baseline file support.
Rust Coverage Script
.github/actions/generate-coverage/scripts/run_rust.py
Replace local baseline reading with shared helper; update function signature and add baseline file support; improve logging.

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Action
    participant Rust Script
    participant Python Script
    participant Baseline File

    GitHub Action->>Rust Script: Run with BASELINE_RUST_FILE env
    Rust Script->>Baseline File: Read previous coverage (if exists)
    Rust Script->>GitHub Action: Log current and previous coverage

    GitHub Action->>Python Script: Run with BASELINE_PYTHON_FILE env
    Python Script->>Baseline File: Read previous coverage (if exists)
    Python Script->>GitHub Action: Log current and previous coverage
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

Coverage numbers on display,
Past and present side by side,
Scripts now whisper what they say—
"Here's your baseline, don't let it slide!"
Logs grow wiser, actions cheer,
Ratcheting progress, year by year.
📈✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/log-current-and-previous-coverage-percentage

🪧 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 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 found some issues that need to be addressed.

  • The new baseline-python-file and baseline-rust-file variables aren’t declared under inputs in action.yml—add those input definitions so the environment vars are actually set.
  • The read_previous function is duplicated in both scripts; consider extracting that logic into a shared utility to reduce maintenance overhead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new baseline-python-file and baseline-rust-file variables aren’t declared under inputs in action.yml—add those input definitions so the environment vars are actually set.
- The read_previous function is duplicated in both scripts; consider extracting that logic into a shared utility to reduce maintenance overhead.

## Individual Comments

### Comment 1
<location> `.github/actions/generate-coverage/scripts/run_python.py:63` </location>
<code_context>
         xml_tmp.unlink(missing_ok=True)


+def read_previous(baseline: Path | None) -> str | None:
+    """Return the previously stored coverage percentage if available."""
+    if baseline and baseline.is_file():
+        try:
+            return f"{float(baseline.read_text().strip()):.2f}"
</code_context>

<issue_to_address>
Consider handling OSError when reading the baseline file.

Only ValueError is currently handled. Catching OSError as well would improve robustness against file access issues.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
def read_previous(baseline: Path | None) -> str | None:
    """Return the previously stored coverage percentage if available."""
    if baseline and baseline.is_file():
        try:
            return f"{float(baseline.read_text().strip()):.2f}"
        except ValueError:
            return None
    return None
=======
def read_previous(baseline: Path | None) -> str | None:
    """Return the previously stored coverage percentage if available."""
    if baseline and baseline.is_file():
        try:
            return f"{float(baseline.read_text().strip()):.2f}"
        except (ValueError, OSError):
            return None
    return None
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `.github/actions/generate-coverage/scripts/run_rust.py:102` </location>
<code_context>
         xml_tmp.unlink(missing_ok=True)


+def read_previous(baseline: Path | None) -> str | None:
+    """Return the previously stored coverage percentage if available."""
+    if baseline and baseline.is_file():
+        try:
+            return f"{float(baseline.read_text().strip()):.2f}"
</code_context>

<issue_to_address>
Consider catching OSError when reading the baseline file.

Currently, only ValueError is handled. To prevent unhandled exceptions from I/O errors, also catch OSError when reading the file.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        try:
            return f"{float(baseline.read_text().strip()):.2f}"
        except ValueError:
            return None
=======
        try:
            return f"{float(baseline.read_text().strip()):.2f}"
        except (ValueError, OSError):
            return None
>>>>>>> REPLACE

</suggested_fix>

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.

Comment thread .github/actions/generate-coverage/scripts/run_python.py Outdated
Comment thread .github/actions/generate-coverage/scripts/run_rust.py
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 732d248 and a2ba751.

📒 Files selected for processing (5)
  • .github/actions/generate-coverage/CHANGELOG.md (1 hunks)
  • .github/actions/generate-coverage/README.md (1 hunks)
  • .github/actions/generate-coverage/action.yml (2 hunks)
  • .github/actions/generate-coverage/scripts/run_python.py (3 hunks)
  • .github/actions/generate-coverage/scripts/run_rust.py (4 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
.github/actions/*/CHANGELOG.md

📄 CodeRabbit Inference Engine (AGENTS.md)

Each action must have a CHANGELOG.md that follows SemVer-based changelog for that action only.

Files:

  • .github/actions/generate-coverage/CHANGELOG.md
.github/actions/*/README.md

📄 CodeRabbit Inference Engine (AGENTS.md)

.github/actions/*/README.md: Each action must have a README.md containing a one-liner summary, table of inputs, table of outputs, usage example with uses: ./.github/actions/<name>@<major>, and a release history link to CHANGELOG.
Add a DEPRECATED: banner to README and repository description when deprecating an action.

Files:

  • .github/actions/generate-coverage/README.md
.github/actions/*/action.yml

📄 CodeRabbit Inference Engine (AGENTS.md)

.github/actions/*/action.yml: Each action must have an action.yml file containing every input and output, with required ones clearly marked.
Composite actions referencing sibling scripts must use ${{ github.action_path }} for portability.

Files:

  • .github/actions/generate-coverage/action.yml
🧬 Code Graph Analysis (1)
.github/actions/generate-coverage/scripts/run_rust.py (1)
.github/actions/generate-coverage/scripts/run_python.py (1)
  • read_previous (63-70)
🪛 LanguageTool
.github/actions/generate-coverage/README.md

[typographical] ~102-~102: The word ‘When’ starts a question. Add a question mark (“?”) at the end of the sentence.
Context: ...the previous percentage is shown as well. Release history is available in [CHANG...

(WRB_QUESTION_MARK)

🔇 Additional comments (11)
.github/actions/generate-coverage/CHANGELOG.md (1)

3-7: LGTM! Changelog entry follows required format.

The changelog entry correctly documents the new logging functionality and follows the SemVer-based format as required by the coding guidelines.

.github/actions/generate-coverage/README.md (1)

100-103: LGTM! Documentation accurately describes the new logging behaviour.

The addition clearly explains when coverage percentages are logged, enhancing user understanding of the action's output.

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

96-96: LGTM! Environment variable correctly passes baseline file path.

The BASELINE_RUST_FILE environment variable properly passes the input parameter to the Rust coverage script.


146-146: LGTM! Environment variable correctly passes baseline file path.

The BASELINE_PYTHON_FILE environment variable properly passes the input parameter to the Python coverage script.

.github/actions/generate-coverage/scripts/run_python.py (4)

28-28: LGTM! Baseline option correctly configured.

The BASELINE_OPT properly reads from the BASELINE_PYTHON_FILE environment variable with appropriate default handling.


63-71: LGTM! Baseline reading function is well-implemented.

The read_previous function correctly handles file existence, reading, and parsing with proper error handling for invalid values.


78-78: LGTM! Function signature correctly updated.

The baseline_file parameter is properly added with the correct type annotation and default value.


99-103: LGTM! Coverage logging implementation is clear and informative.

The logging output provides valuable information about current coverage and conditionally displays previous coverage when available.

.github/actions/generate-coverage/scripts/run_rust.py (3)

34-34: LGTM! Baseline option correctly configured.

The BASELINE_OPT properly reads from the BASELINE_RUST_FILE environment variable with appropriate default handling.


120-120: LGTM! Function signature correctly updated.

The baseline_file parameter is properly added with the correct type annotation and default value.


145-149: LGTM! Coverage logging implementation is clear and informative.

The logging output provides valuable information about current coverage and conditionally displays previous coverage when available, maintaining consistency with the Python implementation.

Comment thread .github/actions/generate-coverage/scripts/run_rust.py
@leynos leynos force-pushed the codex/log-current-and-previous-coverage-percentage branch from f836e97 to 8fd4663 Compare July 31, 2025 11:25
@leynos leynos merged commit c655945 into main Jul 31, 2025
2 checks passed
@leynos leynos deleted the codex/log-current-and-previous-coverage-percentage branch July 31, 2025 12:13
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