Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl live reloading for local runs #1991

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

laststylebender14
Copy link

fixes #1967

@laststylebender14 laststylebender14 marked this pull request as ready for review March 1, 2025 12:23
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR implements live reloading for local development using the bacon crate, allowing automatic application restarts when files change.

  • Added a new --bacon/-b flag to shuttle run in /cargo-shuttle/src/args.rs that enables watch mode
  • Created /cargo-shuttle/src/bacon.rs to handle bacon integration, including version checking (requires 3.8.0+) and configuration
  • Modified /cargo-shuttle/src/lib.rs to conditionally use bacon when the flag is enabled
  • Updated integration tests to include the new flag parameter (set to false by default)

💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!

4 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR simplifies the bacon integration for live reloading in local development environments.

  • Removed redundant default_value = "false" from the bacon flag in cargo-shuttle/src/args.rs as boolean flags are false by default in clap
  • Improved error messaging in cargo-shuttle/src/bacon.rs when bacon is not installed or has an incompatible version
  • Added clear configuration for bacon to restart the application when files change

Greptile AI

2 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

@laststylebender14 laststylebender14 marked this pull request as draft March 1, 2025 12:36
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR finalizes the bacon integration for live reloading with a more robust implementation.

  • Added a constant BACON_CONFIG in cargo-shuttle/src/bacon.rs with proper configuration for killing and restarting processes
  • Improved error handling in check_bacon() with more descriptive error messages when bacon is not installed
  • Enhanced version parsing logic to extract version number from bacon's output

Greptile AI

1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +45 to +47
let version_str = stdout.split_whitespace().nth(1).ok_or_else(|| {
anyhow::anyhow!("Failed to parse bacon version: unexpected output format")
})?;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: The version parsing logic assumes a specific output format from the bacon command. Consider adding a more robust parsing approach that can handle different output formats or version strings.

@laststylebender14 laststylebender14 marked this pull request as ready for review March 1, 2025 13:29
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR completes the implementation of live reloading for local runs by adding platform-specific configurations.

  • Split bacon configuration into platform-specific files with /cargo-shuttle/src/bacon.unix.toml for Unix and /cargo-shuttle/src/bacon.windows.toml for Windows
  • Added conditional compilation in /cargo-shuttle/src/bacon.rs to select the appropriate configuration file based on platform
  • Implemented proper process termination with pkill -TERM -P for Unix and taskkill /F /T /PID for Windows

Greptile AI

3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

This PR adds newline characters to the bacon configuration files for better compatibility with text editors and tools.

  • Added newline at the end of cargo-shuttle/src/bacon.unix.toml for Unix systems
  • Added newline at the end of cargo-shuttle/src/bacon.windows.toml for Windows systems

Greptile AI

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@laststylebender14
Copy link
Author

@jonaro00 can you please review this?

@c-git
Copy link
Contributor

c-git commented Mar 1, 2025

Thanks for working on this. I've been swamped recently.

Copy link
Contributor

@oddgrd oddgrd left a comment

Choose a reason for hiding this comment

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

LGTM, thank you! I left a few comments about using anyhow::Context, but it's just refactoring. Apologies for the delayed review!

.await?
.success()
.then_some(())
.ok_or_else(|| anyhow::anyhow!("bacon process failed"))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Also requires importing anyhow::Context trait.

Suggested change
.ok_or_else(|| anyhow::anyhow!("bacon process failed"))?;
.context("bacon process failed")?;

Comment on lines +44 to +46
let version_str = stdout.split_whitespace().nth(1).ok_or_else(|| {
anyhow::anyhow!("Failed to parse bacon version: unexpected output format")
})?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let version_str = stdout.split_whitespace().nth(1).ok_or_else(|| {
anyhow::anyhow!("Failed to parse bacon version: unexpected output format")
})?;
let version_str = stdout.split_whitespace().nth(1).context("Failed to parse bacon version: unexpected output format")?;

.arg("--version")
.output()
.await
.map_err(|e| anyhow::anyhow!("Failed to execute bacon: {}\nPlease ensure bacon is installed ('cargo install bacon') and you have the necessary permissions", e))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also use context here to add context about the error, and the underlying error will be displayed as a cause, example:

Error: Please ensure bacon is installed ('cargo install bacon') and you have the necessary permissions

Caused by:
    No such file or directory (os error 2)
Suggested change
.map_err(|e| anyhow::anyhow!("Failed to execute bacon: {}\nPlease ensure bacon is installed ('cargo install bacon') and you have the necessary permissions", e))?;
.context("Failed to execute bacon\nPlease ensure bacon is installed ('cargo install bacon') and you have the necessary permissions")?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement]: Bacon live reload on local runs
3 participants