Skip to content

Commit

Permalink
fix: Fix release not being available when installing. (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Jun 19, 2024
1 parent 4c831f7 commit 3288648
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions crates/installer/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,19 @@ pub enum ProtoInstallerError {
#[source]
error: Box<reqwest::Error>,
},

#[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<reqwest::StatusCode>,
},
}
33 changes: 32 additions & 1 deletion crates/installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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(),
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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![
Expand Down

0 comments on commit 3288648

Please sign in to comment.