Skip to content

feat: echo commands in action scripts#54

Merged
leynos merged 2 commits intomainfrom
codex/echo-commands-before-execution-in-python-scripts
Aug 4, 2025
Merged

feat: echo commands in action scripts#54
leynos merged 2 commits intomainfrom
codex/echo-commands-before-execution-in-python-scripts

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Aug 4, 2025

Summary

  • ensure Python helper scripts echo external commands before running them
  • document that scripts log the commands they execute

Testing

  • make lint
  • make test

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

Summary by Sourcery

Echo all external commands before execution in GitHub Action helper scripts and update documentation to reflect this behavior

New Features:

  • Echo each external command prior to execution in generate-coverage, ratchet-coverage, and setup-rust action scripts

Documentation:

  • Document the new command echoing behavior in python-action-scripts.md

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Aug 4, 2025

Reviewer's Guide

This PR enhances action helper scripts by echoing each external command before execution for improved transparency and debugging, and updates documentation to reflect this new behavior.

Sequence diagram for echoing external commands before execution in action scripts

sequenceDiagram
    participant Script as Python Action Script
    participant Typer as Typer (echo)
    participant Shell as Shell/External Command

    Script->>Script: Prepare external command (e.g., cargo, uvx, rsync)
    Script->>Typer: Echo command string (e.g., "$ cargo install ...")
    Typer-->>Script: Command echoed to stdout
    Script->>Shell: Execute external command
    Shell-->>Script: Command output/result
Loading

Class diagram for updated command execution in action scripts

classDiagram
    class ActionScript {
        +main()
        +prepare_command()
        +echo_command()
        +execute_command()
    }
    class Typer {
        +echo(str)
    }
    class ExternalCommand {
        +formulate()
        +run()
    }
    ActionScript --> Typer : uses
    ActionScript --> ExternalCommand : prepares/executes
Loading

File-Level Changes

Change Details Files
Log external commands in action scripts before running them
  • Wrap plumbum and cargo invocations in a cmd variable
  • Insert typer.echo with shlex.join(cmd.formulate()) before executing cmd
  • Maintain original execution patterns (cmd(), cmd & FG, subprocess.check_call)
.github/actions/generate-coverage/scripts/run_python.py
.github/actions/generate-coverage/scripts/run_rust.py
.github/actions/generate-coverage/scripts/install_cargo_llvm_cov.py
.github/actions/generate-coverage/scripts/merge_cobertura.py
.github/actions/ratchet-coverage/scripts/install_cargo_llvm_cov.py
.github/actions/ratchet-coverage/scripts/run_coverage.py
.github/actions/setup-rust/scripts/copy_openbsd_stdlib.py
Document the new command-echo behavior
  • Add note in docs that scripts echo external commands before execution to aid debugging
docs/python-action-scripts.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 Aug 4, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 27 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 8090c3a and d3dfd3f.

📒 Files selected for processing (11)
  • .github/actions/generate-coverage/scripts/install_cargo_llvm_cov.py (1 hunks)
  • .github/actions/generate-coverage/scripts/merge_cobertura.py (2 hunks)
  • .github/actions/generate-coverage/scripts/run_python.py (3 hunks)
  • .github/actions/generate-coverage/scripts/run_rust.py (3 hunks)
  • .github/actions/generate-coverage/tests/test_scripts.py (3 hunks)
  • .github/actions/ratchet-coverage/scripts/install_cargo_llvm_cov.py (1 hunks)
  • .github/actions/ratchet-coverage/scripts/run_coverage.py (2 hunks)
  • .github/actions/setup-rust/scripts/copy_openbsd_stdlib.py (2 hunks)
  • .github/actions/setup-rust/tests/test_copy_stdlib.py (1 hunks)
  • cmd_utils.py (1 hunks)
  • docs/python-action-scripts.md (2 hunks)

Summary by CodeRabbit

  • Documentation

    • Updated documentation to note that all external commands run by Python action scripts are now echoed before execution for improved transparency.
  • Style

    • Added command-line echoing before executing external commands in various scripts, providing clearer visibility of the exact commands being run. This enhances debugging and traceability during script execution.

Walkthrough

Echoing of all shell commands before execution has been introduced across various Python action scripts. This involves importing the shlex module and printing each command line in a shell-escaped format prior to running it. Documentation has been updated to reflect this enhanced transparency and debugging capability.

Changes

Cohort / File(s) Change Summary
Coverage Scripts: Echo Shell Commands
.github/actions/generate-coverage/scripts/install_cargo_llvm_cov.py, .github/actions/generate-coverage/scripts/merge_cobertura.py, .github/actions/generate-coverage/scripts/run_python.py, .github/actions/generate-coverage/scripts/run_rust.py, .github/actions/ratchet-coverage/scripts/install_cargo_llvm_cov.py, .github/actions/ratchet-coverage/scripts/run_coverage.py, .github/actions/setup-rust/scripts/copy_openbsd_stdlib.py
Added import of shlex and print statements to echo the exact shell command before execution in each script. No changes to logic or error handling.
Documentation Update
docs/python-action-scripts.md
Updated documentation to note that all external commands are now echoed before execution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script
    participant Shell

    User->>Script: Run script with arguments
    Script->>Script: Construct command (cmd)
    Script->>User: Echo shell command (shlex.join(cmd))
    Script->>Shell: Execute command
    Shell->>Script: Return output/status
    Script->>User: Display result/output
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

codex

Poem

Before each command, a whisper rings clear,
"Here’s what I’ll run"—so all can hear.
With shlex in hand, the scripts now boast,
Transparent steps, no more hidden ghost.
Debugging’s a breeze, the logs now sing,
Echoes of actions in every string!

✨ 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/echo-commands-before-execution-in-python-scripts

🪧 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.
  • 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.

Support

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

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.

  • Consolidate the echo-and-execute pattern into a shared utility to reduce boilerplate across scripts.
  • Consider sending command echoes to stderr or making them toggleable to avoid mixing with normal stdout/structured outputs.
  • Review whether any sensitive information could be exposed by echoing full commands and consider masking or skipping secrets.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consolidate the echo-and-execute pattern into a shared utility to reduce boilerplate across scripts.
- Consider sending command echoes to stderr or making them toggleable to avoid mixing with normal stdout/structured outputs.
- Review whether any sensitive information could be exposed by echoing full commands and consider masking or skipping secrets.

## Individual Comments

### Comment 1
<location> `.github/actions/generate-coverage/scripts/run_python.py:55` </location>
<code_context>
     try:
-        python["-m", "coverage", "xml", "-o", str(xml_tmp)]()
+        cmd = python["-m", "coverage", "xml", "-o", str(xml_tmp)]
+        typer.echo(f"$ {shlex.join(cmd.formulate())}")
+        cmd()
     except ProcessExecutionError as exc:
</code_context>

<issue_to_address>
Refactor repeated command echoing logic into a helper function to keep code DRY.

The logic for echoing commands before execution is repeated in multiple places. Refactor this into a helper function to avoid duplication and improve maintainability.
</issue_to_address>

### Comment 2
<location> `.github/actions/generate-coverage/scripts/run_rust.py:200` </location>
<code_context>
     try:
-        python["-m", "coverage", "xml", "-o", str(xml_tmp)]()
+        cmd = python["-m", "coverage", "xml", "-o", str(xml_tmp)]
+        typer.echo(f"$ {shlex.join(cmd.formulate())}")
+        cmd()
     except ProcessExecutionError as exc:
</code_context>

<issue_to_address>
Refactor command echoing logic into a reusable function to avoid duplication.

The echoing logic is repeated in several scripts. Refactor it into a helper to keep the code DRY and maintainable.
</issue_to_address>

### Comment 3
<location> `.github/actions/generate-coverage/scripts/install_cargo_llvm_cov.py:19` </location>
<code_context>
     try:
-        python["-m", "coverage", "xml", "-o", str(xml_tmp)]()
+        cmd = python["-m", "coverage", "xml", "-o", str(xml_tmp)]
+        typer.echo(f"$ {shlex.join(cmd.formulate())}")
+        cmd()
     except ProcessExecutionError as exc:
</code_context>

<issue_to_address>
Refactor command echoing into a helper to avoid code duplication.

The echoing logic is repeated. Refactor it into a helper function for better maintainability and DRYness.
</issue_to_address>

### Comment 4
<location> `.github/actions/ratchet-coverage/scripts/run_coverage.py:41` </location>
<code_context>
     try:
-        python["-m", "coverage", "xml", "-o", str(xml_tmp)]()
+        cmd = python["-m", "coverage", "xml", "-o", str(xml_tmp)]
+        typer.echo(f"$ {shlex.join(cmd.formulate())}")
+        cmd()
     except ProcessExecutionError as exc:
</code_context>

<issue_to_address>
Refactor command echoing logic into a helper function to keep code DRY.

The echoing logic is repeated in several places. Refactor it into a helper function to improve code maintainability.
</issue_to_address>

### Comment 5
<location> `.github/actions/setup-rust/scripts/copy_openbsd_stdlib.py:37` </location>
<code_context>

     tmp.mkdir(parents=True, exist_ok=True)
     cmd = ["rsync", "-a", "--delete", f"{artifact_dir}/", str(tmp)]
+    typer.echo(f"$ {shlex.join(cmd)}")
     subprocess.check_call(cmd)  # noqa: S603

</code_context>

<issue_to_address>
Refactor command echoing logic into a helper function to keep code DRY.

The echoing logic is repeated in several places. Refactor it into a helper function to improve code maintainability.
</issue_to_address>

### Comment 6
<location> `docs/python-action-scripts.md:20` </location>
<code_context>
 command execution.  By isolating logic in Python, the composite action YAML
-remains minimal and benefits from better readability and testability.
+remains minimal and benefits from better readability and testability. All
+external commands are echoed before execution to aid debugging and
+transparency.
--- a/.github/actions/generate-coverage/scripts/install_cargo_llvm_cov.py
</code_context>

<issue_to_address>
This line is part of a paragraph that is not wrapped to 80 columns.

Ensure that all lines in paragraphs and bullet points are wrapped to a maximum of 80 columns for readability.
</issue_to_address>

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 Outdated
Comment thread .github/actions/generate-coverage/scripts/install_cargo_llvm_cov.py Outdated
Comment thread .github/actions/ratchet-coverage/scripts/run_coverage.py Outdated
Comment thread .github/actions/setup-rust/scripts/copy_openbsd_stdlib.py Outdated
Comment thread docs/python-action-scripts.md Outdated
@leynos leynos merged commit 8f62e30 into main Aug 4, 2025
2 checks passed
@leynos leynos deleted the codex/echo-commands-before-execution-in-python-scripts branch August 4, 2025 22:26
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