Skip to content

Commit 28fbf05

Browse files
authored
fix(boil): Improve VersionExt::is_floating impl (#1571)
* fix(boil): Improve VersionExt::is_floating impl This commit contains two improvements to the VersionExt::is_floating function: 1. It relaxes the requirements for 0.0.0-dev versions to be able to include extra tag data, eg. 0.0.0-dev-pr123 2. It now uses a regular expression to check whether the prerelease string is considered floating. The previous solution was too limited to catch more complicated patterns. * fix: Use correct nightly Rust version in pre-commit config
1 parent dbcafc0 commit 28fbf05

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ repos:
7878
- id: cargo-rustfmt
7979
name: cargo-rustfmt
8080
language: system
81-
entry: cargo +nightly-2025-10-23 fmt --all -- --check
81+
entry: cargo +nightly-2026-07-01 fmt --all -- --check
8282
stages: [pre-commit, pre-merge-commit]
8383
pass_filenames: false
8484
files: \.rs$

rust/boil/src/utils.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
use std::{process::Command, str::FromStr};
1+
use std::{process::Command, str::FromStr, sync::LazyLock};
22

3+
use regex::Regex;
34
use snafu::{ResultExt, Snafu};
45

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

8+
/// A regular expression to check whether the prerelease string of a semantic version is considered
9+
/// floating.
10+
///
11+
/// Used in [`VersionExt::is_floating`].
12+
static SEMVER_PRERELEASE_FLOATING: LazyLock<Regex> = LazyLock::new(|| {
13+
// 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
14+
Regex::new("^dev(?:-.+)?$|^pr.+$").expect("static regular expression must compile")
15+
});
16+
717
// FIXME (@Techassi): We should pull this in from a central pice of code, like stackable-shared.
818
// stackable-shared needs to add a few features to be able to properly select _only_ what is needed
919
// without pulling in too many unused deps.
@@ -18,7 +28,7 @@ impl VersionExt for semver::Version {
1828
self.major == 0
1929
&& self.minor == 0
2030
&& self.patch == 0
21-
&& (self.pre.starts_with("pr") || self.pre.as_str() == "dev")
31+
&& SEMVER_PRERELEASE_FLOATING.is_match(&self.pre)
2232
}
2333

2434
fn floating(&self) -> String {
@@ -123,3 +133,34 @@ impl CommandExt for Command {
123133
if predicate { self.arg(arg) } else { self }
124134
}
125135
}
136+
137+
#[cfg(test)]
138+
mod tests {
139+
use rstest::rstest;
140+
141+
use super::*;
142+
143+
#[rstest]
144+
#[case("0.0.0-pr1234-extra-tag-data1234-amd64")]
145+
#[case("0.0.0-pr1234-extra-tag-data1234")]
146+
#[case("0.0.0-dev-extra-tag-data1234")]
147+
#[case("0.0.0-pr1234")]
148+
#[case("0.0.0-dev")]
149+
fn is_floating(#[case] input: &str) {
150+
let version =
151+
semver::Version::from_str(input).expect("input must be valid semantic version");
152+
assert!(version.is_floating());
153+
}
154+
155+
#[rstest]
156+
#[case("0.0.0-bar1234-amd64")]
157+
#[case("0.0.0-devel")]
158+
#[case("0.0.0-foo")]
159+
#[case("0.0.0-pr")]
160+
#[case("0.0.0")]
161+
fn is_not_floating(#[case] input: &str) {
162+
let version =
163+
semver::Version::from_str(input).expect("input must be valid semantic version");
164+
assert!(!version.is_floating());
165+
}
166+
}

0 commit comments

Comments
 (0)