Skip to content

Commit

Permalink
feat(fvm): list included artifacts with fvm list <channel> (#3877)
Browse files Browse the repository at this point in the history
* feat(fvm): list included artifacts with `fvm list <channel>`

* fix: doc comment

* feat(fvm): use artifact versions heading in list

* chore(test): test artifact listing
  • Loading branch information
EstebanBorai authored Feb 24, 2024
1 parent 56408e1 commit 0609deb
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 9 deletions.
44 changes: 42 additions & 2 deletions crates/fluvio-version-manager/src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ use clap::Parser;
use colored::Colorize;
use comfy_table::{Table, Row};

use fluvio_hub_util::fvm::Channel;

use crate::common::manifest::VersionManifest;
use crate::common::notify::Notify;
use crate::common::settings::Settings;
use crate::common::version_directory::VersionDirectory;
use crate::common::workdir::fvm_versions_path;

#[derive(Debug, Parser)]
pub struct ListOpt;
pub struct ListOpt {
/// List included artifacts for this installed version if available
#[arg(index = 1)]
channel: Option<Channel>,
}

impl ListOpt {
pub async fn process(&self, notify: Notify) -> Result<()> {
Expand All @@ -30,6 +36,41 @@ impl ListOpt {
return Err(anyhow!("No versions installed"));
}

if let Some(channel) = &self.channel {
let (manifests, _) = VersionDirectory::scan_versions_manifests(versions_path, None)?;
if let Some(manifest) = manifests.iter().find(|m| m.channel == *channel) {
if let Some(contents) = &manifest.contents {
if matches!(manifest.channel, Channel::Tag(_)) {
println!(
"Artifacts in version {}",
manifest.version.to_string().bold()
);
} else {
println!(
"Artifacts in channel {} version {}",
manifest.channel.to_string().bold(),
manifest.version.to_string().bold()
);
}

for art in contents {
println!("{}@{}", art.name, art.version);
}

return Ok(());
}

let suggested_command = format!("{} {}", "fvm install", channel);

notify.help(format!(
"No version contents recorded. You can upadate included artifact details by reinstalling this version. {}",
suggested_command.bold(),
));
}

return Ok(());
}

let settings = Settings::open()?;
let (manifests, maybe_active) =
VersionDirectory::scan_versions_manifests(versions_path, settings.channel)?;
Expand All @@ -45,7 +86,6 @@ impl ListOpt {
}

Self::render_table(manifests, maybe_active);

Ok(())
}

Expand Down
36 changes: 32 additions & 4 deletions crates/fluvio-version-manager/src/common/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,35 @@ use fluvio_hub_util::fvm::Channel;
/// The name of the manifest file for the Package Set
pub const PACKAGE_SET_MANIFEST_FILENAME: &str = "manifest.json";

#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct VersionedArtifact {
pub name: String,
pub version: String,
}

impl VersionedArtifact {
pub fn new<S: Into<String>>(name: S, version: S) -> Self {
Self {
name: name.into(),
version: version.into(),
}
}
}

#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
pub struct VersionManifest {
pub channel: Channel,
pub version: Version,
pub contents: Option<Vec<VersionedArtifact>>,
}

impl VersionManifest {
pub fn new(channel: Channel, version: Version) -> Self {
Self { channel, version }
pub fn new(channel: Channel, version: Version, contents: Vec<VersionedArtifact>) -> Self {
Self {
channel,
version,
contents: Some(contents),
}
}

/// Opens the `manifest.json` file and parses it into a `VersionManifest` struct
Expand Down Expand Up @@ -67,7 +87,11 @@ mod test {
"version": "0.8.0"
}"#;
let tempdir = TempDir::new().unwrap();
let version_manifest = VersionManifest::new(Channel::Stable, Version::new(0, 8, 0));
let version_manifest = VersionManifest::new(
Channel::Stable,
Version::new(0, 8, 0),
vec![VersionedArtifact::new("fluvio", "0.11.4")],
);
let manifest = version_manifest.write(tempdir.path()).unwrap();
let have = read_to_string(manifest).unwrap();

Expand All @@ -77,7 +101,11 @@ mod test {
#[test]
fn reads_manifest_from_json() {
let tempdir = TempDir::new().unwrap();
let version_manifest = VersionManifest::new(Channel::Stable, Version::new(0, 8, 0));
let version_manifest = VersionManifest::new(
Channel::Stable,
Version::new(0, 8, 0),
vec![VersionedArtifact::new("fluvio", "0.11.4")],
);
let json = serde_json::to_string_pretty(&version_manifest).unwrap();
let manifest = version_manifest.write(tempdir.path()).unwrap();
let read_manifest = VersionManifest::open(manifest).unwrap();
Expand Down
1 change: 1 addition & 0 deletions crates/fluvio-version-manager/src/common/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ version = "0.12.0"
let manifest = VersionManifest {
channel: Channel::Stable,
version: Version::parse(VERSION).unwrap(),
contents: None,
};

let mut settings = Settings::open().unwrap();
Expand Down
15 changes: 12 additions & 3 deletions crates/fluvio-version-manager/src/common/version_installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tempfile::TempDir;

use fluvio_hub_util::fvm::{PackageSet, Download, Channel};

use super::manifest::VersionManifest;
use super::manifest::{VersionedArtifact, VersionManifest};
use super::notify::Notify;
use super::version_directory::VersionDirectory;
use super::workdir::fvm_versions_path;
Expand Down Expand Up @@ -46,8 +46,17 @@ impl VersionInstaller {
}

let version_path = self.store_artifacts(&tmp_dir, &self.package_set).await?;
let manifest =
VersionManifest::new(self.channel.to_owned(), self.package_set.pkgset.clone());
let contents = self
.package_set
.artifacts
.iter()
.map(|art| VersionedArtifact::new(art.name.to_owned(), art.version.to_string()))
.collect::<Vec<VersionedArtifact>>();
let manifest = VersionManifest::new(
self.channel.to_owned(),
self.package_set.pkgset.clone(),
contents,
);

manifest.write(&version_path)?;
self.notify.done(format!(
Expand Down
12 changes: 12 additions & 0 deletions tests/cli/fvm_smoke_tests/fvm_basic.bats
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,18 @@ setup_file() {
assert_line --index 2 --partial " 0.10.14 0.10.14"
assert_success

# Checks contents for the stable channel
run bash -c 'fvm list stable'
assert_line --index 0 --partial "Artifacts in channel stable version $STABLE_VERSION"
assert_line --index 1 --partial "fluvio@$STABLE_VERSION"
assert_success

# Checks contents for the version 0.10.14
run bash -c 'fvm list 0.10.14'
assert_line --index 0 --partial "Artifacts in version 0.10.14"
assert_line --index 1 --partial "fluvio@0.10.14"
assert_success

# Checks current command output
run bash -c 'fvm current'
assert_line --index 0 "$STABLE_VERSION (stable)"
Expand Down

0 comments on commit 0609deb

Please sign in to comment.