Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ repos:
- id: cargo-rustfmt
name: cargo-rustfmt
language: system
entry: cargo +nightly-2025-10-23 fmt --all -- --check
entry: cargo +nightly-2026-07-01 fmt --all -- --check
stages: [pre-commit, pre-merge-commit]
pass_filenames: false
files: \.rs$
Expand Down
45 changes: 43 additions & 2 deletions rust/boil/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
use std::{process::Command, str::FromStr};
use std::{process::Command, str::FromStr, sync::LazyLock};

use regex::Regex;
use snafu::{ResultExt, Snafu};

use crate::{cli::HostPort, core::platform::Architecture};

/// A regular expression to check whether the prerelease string of a semantic version is considered
/// floating.
///
/// Used in [`VersionExt::is_floating`].
static SEMVER_PRERELEASE_FLOATING: LazyLock<Regex> = LazyLock::new(|| {
Comment thread
NickLarsenNZ marked this conversation as resolved.
// https://regex101.com/?regex=%5Edev%28%3F%3A-.%2B%29%3F%24%7C%5Epr.%2B%24&testString=dev-pr-321-amd64&flags=gmu&flavor=rust&delimiter=%22
Regex::new("^dev(?:-.+)?$|^pr.+$").expect("static regular expression must compile")
});

// FIXME (@Techassi): We should pull this in from a central pice of code, like stackable-shared.
// stackable-shared needs to add a few features to be able to properly select _only_ what is needed
// without pulling in too many unused deps.
Expand All @@ -18,7 +28,7 @@ impl VersionExt for semver::Version {
self.major == 0
&& self.minor == 0
&& self.patch == 0
&& (self.pre.starts_with("pr") || self.pre.as_str() == "dev")
&& SEMVER_PRERELEASE_FLOATING.is_match(&self.pre)
}

fn floating(&self) -> String {
Expand Down Expand Up @@ -123,3 +133,34 @@ impl CommandExt for Command {
if predicate { self.arg(arg) } else { self }
}
}

#[cfg(test)]
mod tests {
use rstest::rstest;

use super::*;

#[rstest]
#[case("0.0.0-pr1234-extra-tag-data1234-amd64")]
#[case("0.0.0-pr1234-extra-tag-data1234")]
#[case("0.0.0-dev-extra-tag-data1234")]
#[case("0.0.0-pr1234")]
#[case("0.0.0-dev")]
fn is_floating(#[case] input: &str) {
let version =
semver::Version::from_str(input).expect("input must be valid semantic version");
assert!(version.is_floating());
}

#[rstest]
#[case("0.0.0-bar1234-amd64")]
#[case("0.0.0-devel")]
#[case("0.0.0-foo")]
#[case("0.0.0-pr")]
#[case("0.0.0")]
fn is_not_floating(#[case] input: &str) {
let version =
semver::Version::from_str(input).expect("input must be valid semantic version");
assert!(!version.is_floating());
}
}
Loading