@@ -19,6 +19,8 @@ class Check < Baseline::Service
19
19
railties
20
20
)
21
21
22
+ attr_accessor :compat
23
+
22
24
def call ( compat )
23
25
check_uniqueness on_error : :return
24
26
@@ -92,77 +94,78 @@ def check_dependency_supersets
92
94
end
93
95
94
96
# 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 ( /\A Installing (?<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
166
169
167
170
# 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`.
168
171
def check_with_bundler_github
0 commit comments