Skip to content

Commit

Permalink
feat: fluvio cli update check (#2679)
Browse files Browse the repository at this point in the history
Addresses #2071 

Co-authored-by: Dave Beesley <david.beesley@pm.me>
  • Loading branch information
daveatdart and davidbeesley committed Nov 5, 2022
1 parent 6580cb3 commit 6b0e63f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/fluvio-cli-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pub mod user_input;
pub const FLUVIO_RELEASE_CHANNEL: &str = "FLUVIO_RELEASE_CHANNEL";
pub const FLUVIO_EXTENSIONS_DIR: &str = "FLUVIO_EXTENSIONS_DIR";
pub const FLUVIO_IMAGE_TAG_STRATEGY: &str = "FLUVIO_IMAGE_TAG_STRATEGY";
pub const FLUVIO_ALWAYS_CHECK_UPDATES: &str = "FLUVIO_ALWAYS_CHECK_UPDATES";
10 changes: 7 additions & 3 deletions crates/fluvio-cli/src/install/plugins.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Parser;
use fluvio_index::{PackageId, HttpAgent, MaybeVersion};
use super::error_convert;
use super::update::should_always_print_available_update;
use tracing::debug;

use crate::Result;
Expand Down Expand Up @@ -63,9 +64,12 @@ impl InstallOpt {

// After any "install" command, check if the CLI has an available update,
// i.e. one that is not required, but present.
let update_result = check_update_available(&agent, false).await;
if let Ok(Some(latest_version)) = update_result {
prompt_available_update(&latest_version);
// Sometimes this is printed at the beginning, so we don't print it again here
if !should_always_print_available_update() {
let update_result = check_update_available(&agent, false).await;
if let Ok(Some(latest_version)) = update_result {
prompt_available_update(&latest_version);
}
}
Ok(())
}
Expand Down
13 changes: 13 additions & 0 deletions crates/fluvio-cli/src/install/update.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::path::{Path, PathBuf};
use clap::Parser;
use fluvio_channel::{LATEST_CHANNEL_NAME, FLUVIO_RELEASE_CHANNEL};
use fluvio_cli_common::FLUVIO_ALWAYS_CHECK_UPDATES;
use tracing::{debug, instrument};

use semver::Version;
Expand Down Expand Up @@ -298,3 +300,14 @@ pub fn prompt_available_update(latest_version: &Version) {
&latest_version
);
}

pub fn should_always_print_available_update() -> bool {
if std::env::var(FLUVIO_ALWAYS_CHECK_UPDATES).is_ok() {
return true;
}
if let Ok(channel_name) = std::env::var(FLUVIO_RELEASE_CHANNEL) {
channel_name == LATEST_CHANNEL_NAME
} else {
false
}
}
19 changes: 19 additions & 0 deletions crates/fluvio-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ pub(crate) use error::{Result, CliError};
use fluvio_extension_common as common;
pub(crate) const VERSION: &str = include_str!("../../../VERSION");

use fluvio_index::HttpAgent;
use install::update::{
should_always_print_available_update, check_update_available, prompt_available_update,
};
// list of public export
pub use root::{Root, HelpOpt};
pub use client::TableFormatConfig;

mod root {

use crate::check_for_channel_update;
use std::sync::Arc;
use std::path::PathBuf;
use std::process::Command;
Expand Down Expand Up @@ -57,6 +62,7 @@ mod root {

impl Root {
pub async fn process(self) -> Result<()> {
check_for_channel_update().await;
self.command.process(self.opts).await?;
Ok(())
}
Expand Down Expand Up @@ -341,6 +347,19 @@ mod root {
Ok(())
}
}
// Checks for an update if channel is latest or ALWAYS_CHECK is set
async fn check_for_channel_update() {
if should_always_print_available_update() {
println!("🔍 Checking for new version");
let agent = HttpAgent::default();
let update_result = check_update_available(&agent, false).await;
if let Ok(Some(latest_version)) = update_result {
prompt_available_update(&latest_version);
} else {
println!("✅ fluvio-cli is up to date");
}
}
}

mod util {
use fluvio_spu_schema::Isolation;
Expand Down

2 comments on commit 6b0e63f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 6b0e63f Previous: 6580cb3 Ratio
encode wasm file 344863 ns/iter (± 40350) 369704 ns/iter (± 45122) 0.93

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 6b0e63f Previous: 6580cb3 Ratio
vecu8 encoding 319522 ns/iter (± 711680) 398238 ns/iter (± 661017) 0.80
vecu8 decoding 446734 ns/iter (± 431) 581949 ns/iter (± 20067) 0.77
bytebuf encoding 7108 ns/iter (± 61) 18327 ns/iter (± 689) 0.39
bytebuf decoding 6353 ns/iter (± 190) 16874 ns/iter (± 524) 0.38

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.