Skip to content

Commit 41e3d64

Browse files
committed
Stop checking with bundler locally
1 parent 44d3d3b commit 41e3d64

File tree

2 files changed

+117
-71
lines changed

2 files changed

+117
-71
lines changed

app/services/compats/check.rb

Lines changed: 74 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class Check < Baseline::Service
1919
railties
2020
)
2121

22+
attr_accessor :compat
23+
2224
def call(compat)
2325
check_uniqueness on_error: :return
2426

@@ -92,77 +94,78 @@ def check_dependency_supersets
9294
end
9395

9496
# This method checks a compat by actually attempting to install the compat's dependencies with the compat's Rails version locally. If the installation fails, the compat is marked as incompatible. If it succeeds, it is marked as compatible. If any of the dependencies have native extensions that cannot be built, the compat is marked as inconclusive.
95-
def check_with_bundler_locally
96-
return unless @compat.pending? && @compat.check_locally
97-
98-
dir = Rails.root.join("tmp", "compats")
99-
file = dir.join(@compat.id.to_s)
100-
FileUtils.mkdir_p dir
101-
102-
begin
103-
deps_with_rails = @compat.dependencies.dup.tap {
104-
_1["rails"] = [
105-
_1["rails"],
106-
"#{@compat.rails_release.version.approximate_recommendation}.0"
107-
].compact
108-
.join(", ")
109-
}
110-
gemfile_deps = deps_with_rails.map {
111-
quoted_versions = _2.split(/\s*,\s*/).map { |d| "'#{d}'" }
112-
"gem '#{_1}', #{quoted_versions.join(", ")}, require: false"
113-
}
114-
File.write file, <<~SCRIPT
115-
#!/usr/bin/env ruby
116-
117-
require "bundler/inline"
118-
119-
gemfile true do
120-
source "https://rubygems.org"
121-
ruby "#{@compat.rails_release.compatible_ruby_version}"
122-
#{gemfile_deps.join("\n")}
123-
end
124-
SCRIPT
125-
File.chmod 0755, file
126-
127-
stderr, stdout = Bundler.with_unbundled_env do
128-
Open3.popen3 file.to_s do
129-
# For some reason, the order matters: readlines must be called on stderr first. 🤷‍♂️
130-
[_3, _2].map do |io|
131-
io.readlines.map(&:strip)
132-
end
133-
end
134-
end
135-
ensure
136-
if File.exist?(file)
137-
FileUtils.rm_rf file
138-
end
139-
end
140-
141-
stdout.each do |line|
142-
if match = line.match(/\AInstalling (?<name>\S+) (?<version>\S+)\z/)
143-
# TODO: uninstall gem again
144-
end
145-
end
146-
147-
case
148-
when stderr.empty?
149-
@compat.status = :compatible
150-
when stderr.any?(/ERROR: Failed to build gem native extension/)
151-
@compat.status = :inconclusive
152-
when stderr.any?(/You have already activated/)
153-
return
154-
else
155-
unless stderr[0].end_with?("Could not find compatible versions (Bundler::SolveFailure)") &&
156-
stderr.exclude?("Your bundle requires a different version of Bundler than the one you're running.")
157-
158-
raise Error, "Unexpected stderr: #{stderr.join("\n")}"
159-
end
160-
161-
@compat.status = :incompatible
162-
end
163-
164-
@compat.status_determined_by = "bundler_local"
165-
end
97+
# def check_with_bundler_locally
98+
# return unless @compat.pending? && @compat.check_locally
99+
100+
# dir = Rails.root.join("tmp", "compats")
101+
# file = dir.join(@compat.id.to_s)
102+
# FileUtils.mkdir_p dir
103+
104+
# begin
105+
# deps_with_rails = @compat.dependencies.dup.tap {
106+
# _1["rails"] = [
107+
# _1["rails"],
108+
# "#{@compat.rails_release.version.approximate_recommendation}.0"
109+
# ].compact
110+
# .join(", ")
111+
# }
112+
# gemfile_deps = deps_with_rails.map {
113+
# quoted_versions = _2.split(/\s*,\s*/).map { |d| "'#{d}'" }
114+
# "gem '#{_1}', #{quoted_versions.join(", ")}, require: false"
115+
# }
116+
# File.write file, <<~SCRIPT
117+
# #!/usr/bin/env ruby
118+
119+
# require "bundler/inline"
120+
121+
# gemfile true do
122+
# source "https://rubygems.org"
123+
# ruby "#{@compat.rails_release.compatible_ruby_version}"
124+
# #{gemfile_deps.join("\n")}
125+
# end
126+
# SCRIPT
127+
# File.chmod 0755, file
128+
129+
# stderr, stdout = Bundler.with_unbundled_env do
130+
# Open3.popen3 file.to_s do
131+
# # For some reason, the order matters: readlines must be called on stderr first. 🤷‍♂️
132+
# [_3, _2].map do |io|
133+
# io.readlines.map(&:strip)
134+
# end
135+
# end
136+
# end
137+
# ensure
138+
# if File.exist?(file)
139+
# FileUtils.rm_rf file
140+
# end
141+
# end
142+
143+
# stdout.each do |line|
144+
# if match = line.match(/\AInstalling (?<name>\S+) (?<version>\S+)\z/)
145+
# # TODO: uninstall gem again
146+
# end
147+
# end
148+
149+
# case
150+
# when stderr.empty?
151+
# @compat.status = :compatible
152+
# when stderr.any?(/ERROR: Failed to build gem native extension/)
153+
# @compat.status = :inconclusive
154+
# when stderr.any?(/You have already activated/)
155+
# return
156+
# else
157+
# unless stderr[0].end_with?("Could not find compatible versions (Bundler::SolveFailure)") &&
158+
# stderr.exclude?("Your bundle requires a different version of Bundler than the one you're running.")
159+
160+
# raise Error, "Unexpected stderr: #{stderr.join("\n")}"
161+
# end
162+
163+
# @compat.status = :incompatible
164+
# end
165+
166+
# require "byebug"; byebug
167+
# @compat.status_determined_by = "bundler_local"
168+
# end
166169

167170
# This method checks a compat by creating a new branch in the "checker" repository, adding a Gemfile with the compat's dependencies and pushing it to GitHub. A GitHub Actions workflow is then triggered in the "checker" repo, which tries to run `bundler lock` to resolve the dependencies. Afterwards, GitHub sends a notification to the "github_notifications" API endpoint, which creates a new GithubNotification and processes it in `GithubNotifications::Process`.
168171
def check_with_bundler_github

spec/services/compats/check_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,47 @@
2828
end
2929
end
3030
end
31+
32+
xdescribe '#check_with_bundler_locally', vcr: { record: :all } do
33+
before do
34+
FactoryBot.create(:rails_release, version: "7.1")
35+
FactoryBot.create(:rails_release, version: "7.2")
36+
37+
Gemmies::UpdateDependenciesAndVersions.call(gemmy)
38+
Gemmies::UpdateCompats.call(gemmy)
39+
gemmy.reload
40+
end
41+
42+
context 'when using the skunk gem' do
43+
let(:gemmy) { FactoryBot.create(:gemmy, name: 'skunk') }
44+
45+
it 'marks the compat as compatible' do
46+
gemmy.compat_ids.each do |compat_id|
47+
compat = Compat.find(compat_id)
48+
service = described_class.new
49+
service.compat = compat
50+
service.send(:check_with_bundler_locally)
51+
52+
expect(compat.status).to eq('compatible')
53+
expect(compat.status_determined_by).to eq('bundler_local')
54+
end
55+
end
56+
end
57+
58+
context 'when using the win32-api gem' do
59+
let(:gemmy) { FactoryBot.create(:gemmy, name: 'win32-api') }
60+
61+
it 'marks the compat as inconclusive' do
62+
gemmy.compat_ids.each do |compat_id|
63+
compat = Compat.find(compat_id)
64+
service = described_class.new
65+
service.compat = compat
66+
service.send(:check_with_bundler_locally)
67+
68+
expect(compat.status).to eq('inconclusive')
69+
expect(compat.status_determined_by).to eq('bundler_local')
70+
end
71+
end
72+
end
73+
end
3174
end

0 commit comments

Comments
 (0)