diff --git a/CHANGELOG.md b/CHANGELOG.md index c4f976314..a65c1662f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ - [Rust](https://github.com/moonrepo/rust-plugin/blob/master/CHANGELOG.md) - [TOML schema](https://github.com/moonrepo/schema-plugin/blob/master/CHANGELOG.md) +## Unreleased + +#### 🐞 Fixes + +- Fixed `proto upgrade` not working correctly when the release is in progress, or not available yet. + ## 0.37.1 #### 🧩 Plugins diff --git a/crates/cli/src/commands/upgrade.rs b/crates/cli/src/commands/upgrade.rs index 19f0f7e00..a9043d6d3 100644 --- a/crates/cli/src/commands/upgrade.rs +++ b/crates/cli/src/commands/upgrade.rs @@ -65,7 +65,7 @@ pub async fn upgrade(session: ProtoSession) -> AppResult { let upgraded = unpack_release( result, - session.env.store.bin_dir.clone(), + &session.env.store.bin_dir, session .env .store diff --git a/crates/installer/src/error.rs b/crates/installer/src/error.rs index 5b7dfa275..4419751a8 100644 --- a/crates/installer/src/error.rs +++ b/crates/installer/src/error.rs @@ -15,4 +15,19 @@ pub enum ProtoInstallerError { #[source] error: Box, }, + + #[diagnostic( + code(proto::installer::not_available), + help("A release may be in progress, please try again later!"), + url("https://github.com/moonrepo/proto/releases") + )] + #[error( + "Download for proto v{} is not available.\n{}", + .version, + format!("Status: {}", .status).style(Style::MutedLight), + )] + DownloadNotAvailable { + version: String, + status: Box, + }, } diff --git a/crates/installer/src/lib.rs b/crates/installer/src/lib.rs index 6f917c8a8..7f439525c 100644 --- a/crates/installer/src/lib.rs +++ b/crates/installer/src/lib.rs @@ -2,6 +2,7 @@ mod error; use futures::StreamExt; use starbase_archive::Archiver; +use starbase_styles::color; use starbase_utils::fs::{self, FsError}; use std::cmp; use std::env; @@ -11,7 +12,7 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::time::SystemTime; use system_env::SystemLibc; -use tracing::instrument; +use tracing::{instrument, trace}; pub use error::ProtoInstallerError; @@ -58,6 +59,13 @@ pub async fn download_release( let download_url = format!("https://github.com/moonrepo/proto/releases/download/v{version}/{download_file}"); + trace!( + version, + triple, + "Downloading proto release from {}", + color::url(&download_url) + ); + // Request file from url let handle_error = |error: reqwest::Error| ProtoInstallerError::DownloadFailed { url: download_url.clone(), @@ -68,6 +76,15 @@ pub async fn download_release( .send() .await .map_err(handle_error)?; + + if !response.status().is_success() { + return Err(ProtoInstallerError::DownloadNotAvailable { + version: version.to_owned(), + status: Box::new(response.status()), + } + .into()); + } + let total_size = response.content_length().unwrap_or(0); on_chunk(0, total_size); @@ -118,11 +135,23 @@ pub fn unpack_release( vec!["proto", "proto-shim"] }; + trace!( + source = ?download.archive_file, + target = ?temp_dir, + "Unpacking downloaded proto release" + ); + // Unpack the downloaded file Archiver::new(&temp_dir, &download.archive_file).unpack_from_ext()?; // Move the old binaries let relocate = |current_path: &Path, relocate_path: &Path| -> miette::Result<()> { + trace!( + source = ?current_path, + target = ?relocate_path, + "Relocating old proto binary to a new versioned location", + ); + fs::rename(current_path, relocate_path)?; // Track last used so operations like clean continue to work @@ -164,6 +193,8 @@ pub fn unpack_release( // Move the new binary to the bins directory let mut unpacked = false; + trace!(bin_dir = ?install_dir, "Moving unpacked proto binaries to the bin directory"); + for bin_name in &bin_names { let output_path = install_dir.join(bin_name); let input_paths = vec![