Skip to content

Commit 9266aa7

Browse files
authored
Add .ruby-version formats to observability metrics (heroku#1576)
* Normalize observability keys * Capture .ruby-version file information Rails 8 stopped generating `RUBY VERSION` in the Gemfile.lock and started generating a `.ruby-version` file. We will support this file in the future, but there is no spec for it. This commit will observe the formats to help guide implementation decisions. It can also tell us how many people's `.ruby-version` files already align with their `Gemfile.lock` versions. The logic is inside of the bundler wrapper class as this is the first class to read the ruby version from the Gemfile.lock via `$ bundle platform --ruby`. * Changelog
1 parent 951b944 commit 9266aa7

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44

5+
- Observe `.ruby-version` formats (https://github.com/heroku/heroku-buildpack-ruby/pull/1576)
56

67
## [v300] - 2025-04-14
78

lib/language_pack/helpers/bundler_wrapper.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,25 @@ def initialize(options = {})
112112

113113
contents = @gemfile_lock_path.read(mode: "rt")
114114
bundled_with = contents.match(BUNDLED_WITH_REGEX)
115+
dot_ruby_version_file = @gemfile_lock_path.join("..").join(".ruby-version")
115116
@report.capture(
116-
"bundled_with" => bundled_with&.[]("version") || "empty"
117+
"bundler.bundled_with" => bundled_with&.[]("version") || "empty",
118+
# We use this bundler class to detect the Requested ruby version from the Gemfile.lock
119+
# Rails 8 stopped generating `RUBY VERSION` in the Gemfile.lock and started generating
120+
# a `.ruby-version` file. This will observe the formats to help guide implementation
121+
# decisions
122+
"ruby.dot_ruby_version" => dot_ruby_version_file.exist? ? dot_ruby_version_file.read&.strip : nil
117123
)
118124
@version = self.class.detect_bundler_version(
119125
contents: contents,
120126
bundled_with: bundled_with
121127
)
122128
parts = @version.split(".")
123129
@report.capture(
124-
"bundler_version_installed" => @version,
125-
"bundler_major" => parts&.shift,
126-
"bundler_minor" => parts&.shift,
127-
"bundler_patch" => parts&.shift
130+
"bundler.version_installed" => @version,
131+
"bundler.major" => parts&.shift,
132+
"bundler.minor" => parts&.shift,
133+
"bundler.patch" => parts&.shift
128134
)
129135
@dir_name = "bundler-#{@version}"
130136

lib/language_pack/ruby.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def compile
9898
run_assets_precompile_rake_task
9999
end
100100
@report.capture(
101-
"railties_version" => bundler.gem_version('railties'),
102-
"rack_version" => bundler.gem_version('rack')
101+
"gem.railties_version" => bundler.gem_version('railties'),
102+
"gem.rack_version" => bundler.gem_version('rack')
103103
)
104104
config_detect
105105
best_practice_warnings

spec/helpers/bundler_wrapper_spec.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@
6464

6565
expect(report.data).to eq(
6666
{
67-
"bundled_with" => "2.5.7",
68-
"bundler_major" => "2",
69-
"bundler_minor" => "5",
70-
"bundler_patch" => "23",
71-
"bundler_version_installed" => "2.5.23",
67+
"ruby.dot_ruby_version" => nil,
68+
"bundler.bundled_with" => "2.5.7",
69+
"bundler.major" => "2",
70+
"bundler.minor" => "5",
71+
"bundler.patch" => "23",
72+
"bundler.version_installed" => "2.5.23",
7273
}
7374
)
7475
end

0 commit comments

Comments
 (0)