-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces the `fvm update` command which checks current channel to be up to date. Channels `stable` and `latest` are both "updateable", in the other hand the static tag is not "updateable". ### How it works When a user has either `stable` or `latest` as the active channel, FVM fetches the most recent release for that channel. - Stable: Will check if the upstream version is greater than the current using Semver. - Latest: Will check if the upstream tag is different. We cant tell which is greater because we use SHAs to determine versions. - Static Tag: When the user has an static tag as version using for instance `fvm install 0.10.14`, FVM will not attempt to update. Then the same process as for `fvm install` is followed, this is why the logic is first disengaged from `fvm install` into its own module on commit: [0a8b819](0a8b819). In order to determine the current version for the channel FVM uses the already implemented `settings.toml` file. ## Demo ![CleanShot 2023-10-31 at 20 58 13](https://github.com/infinyon/fluvio/assets/34756077/e96d7ac1-043a-4f0b-aa71-2641be254699) > By changing the version in the settings.toml, we can mimic an outdated version for the active channel.
- Loading branch information
1 parent
e2fb300
commit 37a4a3b
Showing
7 changed files
with
352 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ pub mod install; | |
pub mod itself; | ||
pub mod show; | ||
pub mod switch; | ||
pub mod update; | ||
pub mod version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
//! Updates version of the current channel to the most recent one | ||
use anyhow::{Result, Error}; | ||
use clap::Args; | ||
use colored::Colorize; | ||
use url::Url; | ||
|
||
use fluvio_hub_util::HUB_REMOTE; | ||
use fluvio_hub_util::fvm::{Client, DEFAULT_PKGSET, Channel, PackageSet}; | ||
|
||
use crate::common::TARGET; | ||
use crate::common::notify::Notify; | ||
use crate::common::settings::Settings; | ||
use crate::common::version_installer::VersionInstaller; | ||
|
||
#[derive(Debug, Args)] | ||
pub struct UpdateOpt { | ||
/// Registry used to fetch Fluvio Versions | ||
#[arg(long, env = "HUB_REGISTRY_URL", default_value = HUB_REMOTE)] | ||
registry: Url, | ||
} | ||
|
||
impl UpdateOpt { | ||
pub async fn process(self, notify: Notify) -> Result<()> { | ||
let settings = Settings::open()?; | ||
let Some(channel) = settings.channel else { | ||
notify.info("No channel set, please set a channel first using `fvm switch`"); | ||
return Ok(()); | ||
}; | ||
|
||
if channel.is_version_tag() { | ||
// Abort early if the user is not using a Channel and instead has | ||
// a static tag set as active | ||
notify.info("Cannot update a static version tag. You must use a channel."); | ||
return Ok(()); | ||
} | ||
|
||
let latest_pkgset = self.fetch_latest_version(&channel).await?; | ||
let Some(version) = settings.version else { | ||
notify.info( | ||
"No installed version detected, please install a version first using `fvm install`", | ||
); | ||
return Ok(()); | ||
}; | ||
|
||
match channel { | ||
Channel::Stable => { | ||
if latest_pkgset.version > version { | ||
notify.info(format!( | ||
"Updating fluvio {} to version {}. Current version is {}.", | ||
channel.to_string().bold(), | ||
latest_pkgset.version, | ||
version | ||
)); | ||
|
||
return VersionInstaller::new(channel, latest_pkgset, notify) | ||
.install() | ||
.await; | ||
} | ||
|
||
notify.done("You are already up to date"); | ||
} | ||
Channel::Latest => { | ||
// The latest tag can be very dynamic, so we just check for this | ||
// tag to be different than the current version assuming | ||
// upstream is always up to date | ||
if latest_pkgset.version != version { | ||
notify.info(format!( | ||
"Updating fluvio {} to version {}. Current version is {}.", | ||
channel.to_string().bold(), | ||
latest_pkgset.version, | ||
version | ||
)); | ||
|
||
return VersionInstaller::new(channel, latest_pkgset, notify) | ||
.install() | ||
.await; | ||
} | ||
|
||
notify.done("You are already up to date"); | ||
} | ||
Channel::Tag(_) => { | ||
notify.warn("Static tags cannot be updated. No changes made."); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn fetch_latest_version(&self, channel: &Channel) -> Result<PackageSet> { | ||
if channel.is_version_tag() { | ||
return Err(Error::msg( | ||
"Cannot update a static version tag. You must use a channel.", | ||
)); | ||
} | ||
|
||
let client = Client::new(self.registry.as_str())?; | ||
let pkgset = client | ||
.fetch_package_set(DEFAULT_PKGSET, channel, TARGET) | ||
.await?; | ||
|
||
Ok(pkgset) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.