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

Add support for pre-release ruby versions #372

Merged
merged 3 commits into from
Dec 16, 2024
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
1 change: 1 addition & 0 deletions buildpacks/ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Ruby pre-release verssions like `3.4.0.rc1` now work as expected. ([#372](https://github.com/heroku/buildpacks-ruby/pull/372))
- Layer metadata deserialization to Rust structs is now using `#[serde(deny_unknown_fields)]` this prevents the accidental scenario where metadata containing a superset of fields could accidentally be deserialized to the wrong struct. It's unlikely this is currently happening with the current buildpack, but it's a possibly-observable difference so it's being listed ([#371](https://github.com/heroku/buildpacks-ruby/pull/371))

## [4.0.1] - 2024-12-11
Expand Down
81 changes: 75 additions & 6 deletions commons/src/gemfile_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ impl FromStr for GemfileLock {
type Err = std::convert::Infallible;

fn from_str(string: &str) -> Result<Self, Self::Err> {
schneems marked this conversation as resolved.
Show resolved Hide resolved
let bundled_with_re = Regex::new("BUNDLED WITH\\s (\\d+\\.\\d+\\.\\d+)")
.expect("Internal error: Bad regex"); // Checked via clippy
let main_ruby_version_re = Regex::new("RUBY VERSION\\s ruby (\\d+\\.\\d+\\.\\d+)")
.expect("Internal error: Bad regex"); // Checked via clippy
let jruby_version_re =
Regex::new("\\(jruby ((\\d+|\\.)+)\\)").expect("Internal error: Bad regex"); // Checked via clippy
let bundled_with_re =
Regex::new("BUNDLED WITH\\s (\\d+\\.\\d+\\.\\d+)").expect("Clippy checked");
let main_ruby_version_re =
Regex::new("RUBY VERSION\\s ruby (\\d+\\.\\d+\\.\\d+((-|\\.)\\S*\\d+)?)")
.expect("Clippy checked");
let jruby_version_re = Regex::new("\\(jruby ((\\d+|\\.)+)\\)").expect("Clippy checked");

let bundler_version = match bundled_with_re.captures(string).and_then(|c| c.get(1)) {
Some(result) => BundlerVersion::Explicit(result.as_str().to_string()),
Expand Down Expand Up @@ -152,6 +152,75 @@ impl FromStr for GemfileLock {
mod tests {
use super::*;

#[test]
fn test_does_not_capture_patch_version() {
let info = GemfileLock::from_str(
r"
RUBY VERSION
ruby 3.3.5p100

BUNDLED WITH
2.3.4
",
)
.unwrap();

assert_eq!(
info.bundler_version,
BundlerVersion::Explicit("2.3.4".to_string())
);
assert_eq!(
info.ruby_version,
RubyVersion::Explicit("3.3.5".to_string())
);
}

#[test]
fn test_rc_dot_version() {
let info = GemfileLock::from_str(
r"
RUBY VERSION
ruby 3.4.0.rc1

BUNDLED WITH
2.3.4
",
)
.unwrap();

assert_eq!(
info.bundler_version,
BundlerVersion::Explicit("2.3.4".to_string())
);
assert_eq!(
info.ruby_version,
RubyVersion::Explicit("3.4.0.rc1".to_string())
);
}

#[test]
fn test_preview_version() {
let info = GemfileLock::from_str(
r"
RUBY VERSION
ruby 3.4.0.preview2

BUNDLED WITH
2.3.4
",
)
.unwrap();

assert_eq!(
info.bundler_version,
BundlerVersion::Explicit("2.3.4".to_string())
);
assert_eq!(
info.ruby_version,
RubyVersion::Explicit("3.4.0.preview2".to_string())
);
}

#[test]
fn test_parse_gemfile_lock() {
let info = GemfileLock::from_str(
Expand Down