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(cargo-shuttle): Add upgrade subcommand to run install script #1848

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ pub enum Command {
Generate(GenerateCommand),
/// Open an issue on GitHub and provide feedback
Feedback,
/// Upgrade the cargo-shuttle binary
Upgrade {
/// Install an unreleased version from the repository's main branch
#[arg(long)]
preview: bool,
},
}

#[derive(Parser)]
Expand Down
42 changes: 40 additions & 2 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use shuttle_common::{
constants::{
headers::X_CARGO_SHUTTLE_VERSION, API_URL_BETA, API_URL_DEFAULT, DEFAULT_IDLE_MINUTES,
EXAMPLES_REPO, EXECUTABLE_DIRNAME, RESOURCE_SCHEMA_VERSION, RUNTIME_NAME,
SHUTTLE_GH_ISSUE_URL, SHUTTLE_IDLE_DOCS_URL, SHUTTLE_INSTALL_DOCS_URL, SHUTTLE_LOGIN_URL,
STORAGE_DIRNAME, TEMPLATES_SCHEMA_VERSION,
SHUTTLE_GH_ISSUE_URL, SHUTTLE_GH_REPO_URL, SHUTTLE_IDLE_DOCS_URL, SHUTTLE_INSTALL_DOCS_URL,
SHUTTLE_LOGIN_URL, STORAGE_DIRNAME, TEMPLATES_SCHEMA_VERSION,
},
deployment::{DeploymentStateBeta, DEPLOYER_END_MESSAGES_BAD, DEPLOYER_END_MESSAGES_GOOD},
log::LogsRange,
Expand Down Expand Up @@ -338,6 +338,7 @@ impl Shuttle {
ProjectCommand::Stop => self.project_stop().await,
ProjectCommand::Delete(ConfirmationArgs { yes }) => self.project_delete(yes).await,
},
Command::Upgrade { preview } => update_cargo_shuttle(preview).await,
};

for w in self.version_warnings {
Expand Down Expand Up @@ -3236,6 +3237,43 @@ fn create_spinner() -> ProgressBar {
pb
}

async fn update_cargo_shuttle(preview: bool) -> Result<()> {
if preview {
let _ = tokio::process::Command::new("cargo")
.args(["install", "cargo-shuttle", "--git", SHUTTLE_GH_REPO_URL])
.kill_on_drop(true)
.spawn()
.context("Failed to spawn cargo install process")?
.wait()
.await
.context("Failed to wait on cargo install process")?;

return Ok(());
}

#[cfg(target_family = "unix")]
let _ = tokio::process::Command::new("bash")
.args(["-c", "curl -sSfL https://www.shuttle.rs/install | bash"])
.kill_on_drop(true)
.spawn()
.context("Failed to spawn bash update process")?
.wait()
.await
.context("Failed to wait on bash update process")?;

#[cfg(target_family = "windows")]
let _ = tokio::process::Command::new("powershell")
.args(["-Command", "iwr https://www.shuttle.rs/install-win | iex"])
.kill_on_drop(true)
.spawn()
.context("Failed to spawn powershell update process")?
.wait()
.await
.context("Failed to wait on powershell update process")?;

Ok(())
}

#[cfg(test)]
mod tests {
use flate2::read::GzDecoder;
Expand Down
1 change: 1 addition & 0 deletions common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub const API_URL_DEFAULT: &str = API_URL_PRODUCTION;

pub const SHUTTLE_STATUS_URL: &str = "https://status.shuttle.rs";
pub const SHUTTLE_LOGIN_URL: &str = "https://console.shuttle.rs/new-project";
pub const SHUTTLE_GH_REPO_URL: &str = "https://github.com/shuttle-hq/shuttle";
pub const SHUTTLE_GH_ISSUE_URL: &str = "https://github.com/shuttle-hq/shuttle/issues/new/choose";
pub const SHUTTLE_INSTALL_DOCS_URL: &str = "https://docs.shuttle.rs/getting-started/installation";
pub const SHUTTLE_IDLE_DOCS_URL: &str = "https://docs.shuttle.rs/getting-started/idle-projects";
Expand Down