Skip to content

Commit

Permalink
feat(cargo-shuttle): Add upgrade subcommand to run install script (#…
Browse files Browse the repository at this point in the history
…1848)

* feat(cargo-shuttle): Add `upgrade` subcommand to run install script

* feat: add --preview flag

---------

Co-authored-by: jonaro00 <54029719+jonaro00@users.noreply.github.com>
  • Loading branch information
supleed2 and jonaro00 authored Sep 19, 2024
1 parent bb7b6be commit 243daff
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
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

0 comments on commit 243daff

Please sign in to comment.