Skip to content

Commit ef32c0b

Browse files
authored
Add support for pre-release ruby versions (#372)
* Add support for pre-release ruby versions Pre-releases in ruby use either `-` or `.` and touch the last number, versus patch identifiers start with `p`. This commit now captures identifiers such as `.rc1` or `.preview2` The state of tooling is confusing, as different tools manipulate values differently: ``` $ cat Gemfile source 'https://rubygems.org' ruby "3.4.0-rc1" gem 'rake' ⛄️ 3.4.0 🚀 /private/tmp/aa82068ba3124d84c76d7faf156888a5 (main) $ cat Gemfile.lock GEM remote: https://rubygems.org/ specs: rake (13.2.1) PLATFORMS arm64-darwin-23 ruby DEPENDENCIES rake RUBY VERSION ruby 3.4.0.rc1 BUNDLED WITH 2.5.23 ``` Here's some more context: - https://github.com/heroku/docker-heroku-ruby-builder/blob/175b5c15104cb809e1a0adc2c2a9902f94083954/lib/version_parts.rb#L1-L57 - https://github.com/heroku/docker-heroku-ruby-builder/blob/a41f31c72a74df6bcb4f9266e12192b0af83da98/shared/src/download_ruby_version.rs#L73-L93 Our versions are stored on S3 like this: ``` s3://heroku-buildpack-ruby/heroku-24/arm64/ruby-3.4.0.rc1.tgz ``` * Move clippy comments into expect statements * Changelog
1 parent a79408d commit ef32c0b

File tree

2 files changed

+76
-6
lines changed

2 files changed

+76
-6
lines changed

buildpacks/ruby/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
- Ruby pre-release verssions like `3.4.0.rc1` now work as expected. ([#372](https://github.com/heroku/buildpacks-ruby/pull/372))
1213
- 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))
1314

1415
## [4.0.1] - 2024-12-11

commons/src/gemfile_lock.rs

+75-6
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ impl FromStr for GemfileLock {
116116
type Err = std::convert::Infallible;
117117

118118
fn from_str(string: &str) -> Result<Self, Self::Err> {
119-
let bundled_with_re = Regex::new("BUNDLED WITH\\s (\\d+\\.\\d+\\.\\d+)")
120-
.expect("Internal error: Bad regex"); // Checked via clippy
121-
let main_ruby_version_re = Regex::new("RUBY VERSION\\s ruby (\\d+\\.\\d+\\.\\d+)")
122-
.expect("Internal error: Bad regex"); // Checked via clippy
123-
let jruby_version_re =
124-
Regex::new("\\(jruby ((\\d+|\\.)+)\\)").expect("Internal error: Bad regex"); // Checked via clippy
119+
let bundled_with_re =
120+
Regex::new("BUNDLED WITH\\s (\\d+\\.\\d+\\.\\d+)").expect("Clippy checked");
121+
let main_ruby_version_re =
122+
Regex::new("RUBY VERSION\\s ruby (\\d+\\.\\d+\\.\\d+((-|\\.)\\S*\\d+)?)")
123+
.expect("Clippy checked");
124+
let jruby_version_re = Regex::new("\\(jruby ((\\d+|\\.)+)\\)").expect("Clippy checked");
125125

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

155+
#[test]
156+
fn test_does_not_capture_patch_version() {
157+
let info = GemfileLock::from_str(
158+
r"
159+
RUBY VERSION
160+
ruby 3.3.5p100
161+
162+
BUNDLED WITH
163+
2.3.4
164+
",
165+
)
166+
.unwrap();
167+
168+
assert_eq!(
169+
info.bundler_version,
170+
BundlerVersion::Explicit("2.3.4".to_string())
171+
);
172+
assert_eq!(
173+
info.ruby_version,
174+
RubyVersion::Explicit("3.3.5".to_string())
175+
);
176+
}
177+
178+
#[test]
179+
fn test_rc_dot_version() {
180+
let info = GemfileLock::from_str(
181+
r"
182+
RUBY VERSION
183+
ruby 3.4.0.rc1
184+
185+
BUNDLED WITH
186+
2.3.4
187+
",
188+
)
189+
.unwrap();
190+
191+
assert_eq!(
192+
info.bundler_version,
193+
BundlerVersion::Explicit("2.3.4".to_string())
194+
);
195+
assert_eq!(
196+
info.ruby_version,
197+
RubyVersion::Explicit("3.4.0.rc1".to_string())
198+
);
199+
}
200+
201+
#[test]
202+
fn test_preview_version() {
203+
let info = GemfileLock::from_str(
204+
r"
205+
RUBY VERSION
206+
ruby 3.4.0.preview2
207+
208+
BUNDLED WITH
209+
2.3.4
210+
",
211+
)
212+
.unwrap();
213+
214+
assert_eq!(
215+
info.bundler_version,
216+
BundlerVersion::Explicit("2.3.4".to_string())
217+
);
218+
assert_eq!(
219+
info.ruby_version,
220+
RubyVersion::Explicit("3.4.0.preview2".to_string())
221+
);
222+
}
223+
155224
#[test]
156225
fn test_parse_gemfile_lock() {
157226
let info = GemfileLock::from_str(

0 commit comments

Comments
 (0)