From 50c10f77c75a79fa6c9c4e64b27da2ee1af9bd44 Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Sun, 28 Jul 2024 19:01:01 +0100 Subject: [PATCH 1/2] feat(cargo-shuttle): Add `upgrade` subcommand to run install script --- cargo-shuttle/src/args.rs | 2 ++ cargo-shuttle/src/lib.rs | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/cargo-shuttle/src/args.rs b/cargo-shuttle/src/args.rs index adcddda03..94037024b 100644 --- a/cargo-shuttle/src/args.rs +++ b/cargo-shuttle/src/args.rs @@ -131,6 +131,8 @@ pub enum Command { Generate(GenerateCommand), /// Open an issue on GitHub and provide feedback Feedback, + /// Upgrade the cargo-shuttle binary + Upgrade, } #[derive(Parser)] diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 6fe20c772..fa0306800 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -284,6 +284,7 @@ impl Shuttle { ProjectCommand::Stop => self.project_stop().await, ProjectCommand::Delete(ConfirmationArgs { yes }) => self.project_delete(yes).await, }, + Command::Upgrade => update_cargo_shuttle().await, }; for w in self.version_warnings { @@ -2965,6 +2966,30 @@ pub enum CommandOutcome { DeploymentFailure, } +async fn update_cargo_shuttle() -> Result { + #[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(CommandOutcome::Ok) +} + #[cfg(test)] mod tests { use flate2::read::GzDecoder; From 400ed06e23142e38ad32c0a019d25ae9439a4260 Mon Sep 17 00:00:00 2001 From: jonaro00 <54029719+jonaro00@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:05:51 +0200 Subject: [PATCH 2/2] feat: add --preview flag --- cargo-shuttle/src/args.rs | 6 +++++- cargo-shuttle/src/lib.rs | 21 +++++++++++++++++---- common/src/constants.rs | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cargo-shuttle/src/args.rs b/cargo-shuttle/src/args.rs index 782610958..8b542a1c8 100644 --- a/cargo-shuttle/src/args.rs +++ b/cargo-shuttle/src/args.rs @@ -138,7 +138,11 @@ pub enum Command { /// Open an issue on GitHub and provide feedback Feedback, /// Upgrade the cargo-shuttle binary - Upgrade, + Upgrade { + /// Install an unreleased version from the repository's main branch + #[arg(long)] + preview: bool, + }, } #[derive(Parser)] diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index fff04dec9..ea1527055 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -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, @@ -338,7 +338,7 @@ impl Shuttle { ProjectCommand::Stop => self.project_stop().await, ProjectCommand::Delete(ConfirmationArgs { yes }) => self.project_delete(yes).await, }, - Command::Upgrade => update_cargo_shuttle().await, + Command::Upgrade { preview } => update_cargo_shuttle(preview).await, }; for w in self.version_warnings { @@ -3237,7 +3237,20 @@ fn create_spinner() -> ProgressBar { pb } -async fn update_cargo_shuttle() -> Result<()> { +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"]) diff --git a/common/src/constants.rs b/common/src/constants.rs index bc777aa5c..fb1d92006 100644 --- a/common/src/constants.rs +++ b/common/src/constants.rs @@ -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";