Skip to content

Commit

Permalink
fix: correctly sort helm versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dj95 committed Dec 17, 2023
1 parent 3de0eeb commit c9561c2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 25 deletions.
76 changes: 56 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ serde_yaml = "0.9.21"
tokio = { version = "1.28.2", features = ["full"] }
tower = "0.4.13"
tower-http = "0.4.0"
versions = "6.0.0"
9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lint:
cargo clippy --all-targets --all-features -- -D warnings
cargo audit

run namespace:
cargo run -- -n {{namespace}}

test:
cargo test --all-targets --all-features
23 changes: 18 additions & 5 deletions src/helm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,24 @@ impl HelmRepoIndex {
bail!("cannot find chart");
}

let mut versions = versions.unwrap().clone();
versions.sort_by(|a, b| a.created.cmp(&b.created).reverse());

return match versions.first() {
Some(version) => Ok(version.version.to_string()),
let mut semvers: Vec<_> = versions
.unwrap()
.iter()
.filter_map(|v| {
let mut ver = v.version.clone();
if v.version.starts_with('v') {
ver = ver[1..].to_string();
}
versions::SemVer::new(&ver).map(|sv| (sv, v.version.clone()))
})
.filter(|(v, _)| v.pre_rel.is_none())
.collect();

semvers.sort();
semvers.reverse();

return match semvers.first() {
Some(version) => Ok(version.1.to_string()),
None => bail!("cannot get newest version"),
};
}
Expand Down

0 comments on commit c9561c2

Please sign in to comment.