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(cli): Reimplement the webc upload progress bar #4693

Merged
merged 2 commits into from
May 14, 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
8 changes: 8 additions & 0 deletions lib/cli/src/commands/package/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{
};
use colored::Colorize;
use dialoguer::Confirm;
use indicatif::{ProgressBar, ProgressStyle};
use std::{
collections::BTreeMap,
path::{Path, PathBuf},
Expand Down Expand Up @@ -41,6 +42,7 @@ pub(super) async fn upload(
hash: &PackageHash,
timeout: humantime::Duration,
package: &Package,
pb: &ProgressBar,
) -> anyhow::Result<String> {
let hash_str = hash.to_string();
let hash_str = hash_str.trim_start_matches("sha256:");
Expand Down Expand Up @@ -114,6 +116,11 @@ pub(super) async fn upload(
let bytes = package.serialize()?;

let total_bytes = bytes.len();
pb.set_length(total_bytes.try_into().unwrap());
pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{bar:.cyan/blue}] {bytes}/{total_bytes} ({bytes_per_sec}, {eta})")
.unwrap()
.progress_chars("█▉▊▋▌▍▎▏ ")
.tick_strings(&["✶", "✸", "✹", "✺", "✹", "✷"]));
tracing::info!("webc is {total_bytes} bytes long");

let chunk_size = 1_048_576; // 1MB - 315s / 100MB
Expand Down Expand Up @@ -144,6 +151,7 @@ pub(super) async fn upload(
})??;

total_bytes_sent += n;
pb.set_position(total_bytes_sent.try_into().unwrap());
}

Ok(url)
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/package/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl PackagePush {
) -> anyhow::Result<()> {
let pb = make_spinner!(self.quiet, "Uploading the package to the registry..");

let signed_url = upload(client, package_hash, self.timeout, package).await?;
let signed_url = upload(client, package_hash, self.timeout, package, &pb).await?;

let id = match wasmer_api::query::push_package_release(
client,
Expand Down
Loading