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

fix: Sort operator versions by semver version #336

Merged
merged 13 commits into from
Nov 20, 2024
5 changes: 5 additions & 0 deletions rust/stackablectl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ All notable changes to this project will be documented in this file.
[CVE-2024-45311] ([#318]).
- Bump Rust toolchain version to 1.80.1 ([#318]).

### Fixed

- Sort operator versions by semver version instead of alphabetically ([#336]).

[#318]: https://github.com/stackabletech/stackable-cockpit/pull/318
[#336]: https://github.com/stackabletech/stackable-cockpit/pull/336
[CVE-2024-45311]: https://github.com/advisories/GHSA-vr26-jcq5-fjj8

## [24.7.1] - 2024-08-15
Expand Down
21 changes: 13 additions & 8 deletions rust/stackablectl/src/cmds/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ pub enum CmdError {
#[snafu(display("invalid repository name"))]
InvalidRepoName { source: InvalidRepoNameError },

#[snafu(display("invalid helm chart version {version:?} (need to be semver)"))]
sbernauer marked this conversation as resolved.
Show resolved Hide resolved
InvalidHelmChartVersion {
source: semver::Error,
version: String,
},

#[snafu(display("unknown repository name '{name}'"))]
UnknownRepoName { name: String },

Expand Down Expand Up @@ -524,16 +530,15 @@ where
Some(entries) => {
let mut versions = entries
.iter()
.map(|e| Version::parse(&e.version))
.map_while(|r| match r {
Ok(v) => Some(v),
Err(_) => None,
.map(|entry| {
Version::parse(&entry.version).context(InvalidHelmChartVersionSnafu {
sbernauer marked this conversation as resolved.
Show resolved Hide resolved
version: entry.version.clone(),
})
})
.map(|v| v.to_string())
.collect::<Vec<String>>();

.collect::<Result<Vec<_>, _>>()?;
versions.sort();
Ok(versions)

Ok(versions.iter().map(|version| version.to_string()).collect())
}
None => Ok(vec![]),
}
Expand Down
Loading