Skip to content

Commit c8ab729

Browse files
authored
Track origin of Ruby version (heroku#1636)
* Track origin of Ruby version Previously "default" was a boolean. In the future we will add other locations such as the `.ruby-version` file. GUS-W-19310637 * Track unique version number Both JRuby and MRI share the same `ruby.version` value. i.e. `3.4.2` to distinguish we are switching to the `version-for-download` which includes the information about the engine, this will make queries more clear whether they include jruby or not. The prior value is moved to "spec" version as engines such as JRuby will implement to a spec such as `3.4.2`. GUS-W-19310643 * Update key names Brings key names closer to python's https://github.com/heroku/heroku-buildpack-python/blob/3c27de9acc7a7bbcaf27d281e1381cd81c793999/bin/report#L69-L72. Adds docs over each since the names alone might be confusing.
1 parent a6d1244 commit c8ab729

4 files changed

Lines changed: 94 additions & 23 deletions

File tree

lib/language_pack/installers/heroku_ruby_installer.rb

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,36 @@ def initialize(stack: , multi_arch_stacks: , arch: , report: HerokuBuildReport::
2121

2222
def install(ruby_version, install_dir)
2323
@report.capture(
24-
"ruby.version" => ruby_version.ruby_version,
25-
"ruby.engine" => ruby_version.engine,
26-
"ruby.engine.version" => ruby_version.engine_version,
27-
"ruby.major" => ruby_version.major,
28-
"ruby.minor" => ruby_version.minor,
29-
"ruby.patch" => ruby_version.patch,
30-
"ruby.default" => ruby_version.default?,
24+
# i.e. `jruby` or `ruby`
25+
"ruby_version_engine" => ruby_version.engine,
26+
# i.e. `ruby-3.4.2-jruby-10.0.2.0` or `ruby-3.4.2` or `ruby-3.5.0.pre1`
27+
"ruby_version_unique" => ruby_version.version_for_download,
28+
# i.e. `default` or `Gemfile.lock`
29+
"ruby_version_origin" => ruby_version.default? ? "default" : "Gemfile.lock",
3130
)
31+
32+
case ruby_version.engine
33+
when :ruby
34+
@report.capture(
35+
"ruby_version_major_minor" => "#{ruby_version.major}.#{ruby_version.minor}",
36+
"ruby_version_full" => ruby_version.engine_version_full
37+
)
38+
when :jruby
39+
@report.capture(
40+
# i.e. `3.4.2` the target spec ruby version
41+
"jruby_version_ruby_version" => ruby_version.ruby_version,
42+
# i.e. `10.0.2.0` the version of jruby
43+
"jruby_version_full" => ruby_version.engine_version_full,
44+
# i.e. `9.4` or `10.0`
45+
"jruby_version_major_minor" => [
46+
ruby_version.engine_version.split(".")[0],
47+
ruby_version.engine_version.split(".")[1]
48+
].join(".")
49+
)
50+
else
51+
raise "Internal error: Unknown engine: #{ruby_version.engine}"
52+
end
53+
3254
fetch_unpack(ruby_version, install_dir)
3355
setup_binstubs(install_dir)
3456
end

lib/language_pack/ruby_version.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,26 @@ def initialize(
8888
@engine_version = engine_version
8989
end
9090

91+
# Also used as for metrics to track unique installs
9192
# i.e. `ruby-3.4.2`
9293
def version_for_download
9394
if @engine == :jruby
9495
"ruby-#{ruby_version}-jruby-#{engine_version}"
96+
else
97+
"ruby-#{engine_version_full}"
98+
end
99+
end
100+
101+
# Full qualifier for the version including pre-release information
102+
# i.e. `3.5.0.preview1` or `3.5.0` or `3.5.0.rc1` for ruby
103+
# i.e. `9.4.9.0` for jruby
104+
def engine_version_full
105+
if @engine == :jruby
106+
engine_version
95107
elsif @pre
96-
"ruby-#{ruby_version}.#{@pre}"
108+
"#{engine_version}.#{@pre}"
97109
else
98-
"ruby-#{ruby_version}"
110+
"#{engine_version}"
99111
end
100112
end
101113

spec/hatchet/ruby_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
expect(report_match).to be_truthy
190190
yaml = report_match[:yaml].gsub(/remote: /, "")
191191
report = YAML.load(yaml)
192-
expect(report.fetch("ruby.version")).to eq(expected)
192+
expect(report.fetch("ruby_version_full")).to eq(expected)
193193
rescue Exception => e
194194
puts app.output
195195
puts yaml if yaml

spec/helpers/heroku_ruby_installer_spec.rb

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def installer(report: HerokuBuildReport::GLOBAL)
1010
)
1111
end
1212

13+
def sort_hash(hash)
14+
hash.sort_by { |k, _| k.to_s }.to_h
15+
end
16+
1317
def ruby_version
1418
LanguagePack::RubyVersion.bundle_platform_ruby(bundler_output: "ruby-3.1.7")
1519
end
@@ -26,7 +30,7 @@ def ruby_version
2630
end
2731
end
2832

29-
describe "#install" do
33+
describe "ruby installation" do
3034
it "should install ruby and setup binstubs" do
3135
Dir.mktmpdir do |dir|
3236
Dir.chdir(dir) do
@@ -37,12 +41,41 @@ def ruby_version
3741
expect(File.symlink?("#{dir}/bin/ruby.exe")).to be true
3842
expect(File).to exist("#{dir}/vendor/ruby/bin/ruby")
3943

40-
expect(report.data["ruby.version"]).to eq("3.1.7")
41-
expect(report.data["ruby.engine"]).to eq(:ruby)
42-
expect(report.data["ruby.engine.version"]).to eq(report.data["ruby.version"])
43-
expect(report.data["ruby.major"]).to eq(3)
44-
expect(report.data["ruby.minor"]).to eq(1)
45-
expect(report.data["ruby.patch"]).to eq(7)
44+
expected = {
45+
"ruby_version_engine" => :ruby,
46+
"ruby_version_full" => "3.1.7",
47+
"ruby_version_major_minor" => "3.1",
48+
"ruby_version_origin" => "Gemfile.lock",
49+
"ruby_version_unique" => "ruby-3.1.7"
50+
}
51+
52+
expect(sort_hash(report.data)).to eq(sort_hash(expected))
53+
end
54+
end
55+
end
56+
57+
it "should work with pre-release versions" do
58+
Dir.mktmpdir do |dir|
59+
Dir.chdir(dir) do
60+
report = HerokuBuildReport.dev_null
61+
installer(report: report).install(
62+
LanguagePack::RubyVersion.bundle_platform_ruby(bundler_output: "ruby-3.5.0.preview1"),
63+
"#{dir}/vendor/ruby"
64+
)
65+
66+
expect(File.symlink?("#{dir}/bin/ruby")).to be true
67+
expect(File.symlink?("#{dir}/bin/ruby.exe")).to be true
68+
expect(File).to exist("#{dir}/vendor/ruby/bin/ruby")
69+
70+
expected = {
71+
"ruby_version_engine" => :ruby,
72+
"ruby_version_major_minor" => "3.5",
73+
"ruby_version_full" => "3.5.0.preview1",
74+
"ruby_version_origin" => "Gemfile.lock",
75+
"ruby_version_unique" => "ruby-3.5.0.preview1"
76+
}
77+
78+
expect(sort_hash(report.data)).to eq(sort_hash(expected))
4679
end
4780
end
4881
end
@@ -62,12 +95,16 @@ def ruby_version
6295
"#{dir}/vendor/ruby"
6396
)
6497

65-
expect(report.data["ruby.version"]).to eq("3.1.4")
66-
expect(report.data["ruby.engine"]).to eq(:jruby)
67-
expect(report.data["ruby.engine.version"]).to eq("9.4.9.0")
68-
expect(report.data["ruby.major"]).to eq(3)
69-
expect(report.data["ruby.minor"]).to eq(1)
70-
expect(report.data["ruby.patch"]).to eq(4)
98+
expected = {
99+
"ruby_version_engine" => :jruby,
100+
"jruby_version_full" => "9.4.9.0",
101+
"jruby_version_major_minor" => "9.4",
102+
"jruby_version_ruby_version" => "3.1.4",
103+
"ruby_version_origin" => "Gemfile.lock",
104+
"ruby_version_unique" => "ruby-3.1.4-jruby-9.4.9.0"
105+
}
106+
107+
expect(sort_hash(report.data)).to eq(sort_hash(expected))
71108
end
72109
end
73110
end

0 commit comments

Comments
 (0)