Skip to content

Commit 55907c7

Browse files
Merge branch 'master' into MONGOID-5136-super-touch
2 parents 17c9a09 + ebeec99 commit 55907c7

File tree

73 files changed

+1396
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1396
-421
lines changed

.evergreen/config.yml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,6 @@ axes:
404404
- id: "ruby"
405405
display_name: Ruby Version
406406
values:
407-
- id: "ruby-2.3"
408-
display_name: ruby-2.3
409-
variables:
410-
RVM_RUBY: "ruby-2.3"
411-
- id: "ruby-2.4"
412-
display_name: ruby-2.4
413-
variables:
414-
RVM_RUBY: "ruby-2.4"
415407
- id: "ruby-2.5"
416408
display_name: ruby-2.5
417409
variables:
@@ -599,30 +591,6 @@ buildvariants:
599591
tasks:
600592
- name: "test"
601593

602-
- matrix_name: "ruby-2.4"
603-
matrix_spec:
604-
ruby: ["ruby-2.4"]
605-
driver: ["current"]
606-
topology: ['replica-set', 'sharded-cluster']
607-
mongodb-version: ['3.2', '3.4']
608-
display_name: "${ruby}, ${driver}, ${rails}, ${mongodb-version}, ${topology}"
609-
run_on:
610-
- ubuntu1604-small
611-
tasks:
612-
- name: "test"
613-
614-
- matrix_name: "ruby-2.3"
615-
matrix_spec:
616-
ruby: ["ruby-2.3"]
617-
driver: ["current"]
618-
topology: ['replica-set', 'sharded-cluster']
619-
mongodb-version: ['2.6', '3.0']
620-
display_name: "${ruby}, ${driver}, ${rails}, ${mongodb-version}, ${topology}"
621-
run_on:
622-
- ubuntu1604-small
623-
tasks:
624-
- name: "test"
625-
626594
- matrix_name: "driver-upcoming"
627595
matrix_spec:
628596
driver: [master, stable]

.evergreen/make-github-actions

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
#!/usr/bin/env ruby
2+
3+
# TODO: Support topology=sharded-cluster (requires better MongoDB Github Action)
4+
# TODO: Support i18n-fallbacks test
5+
# TODO: Support app-tests tests
6+
7+
require 'fileutils'
8+
require 'active_support/dependencies/autoload'
9+
require 'active_support/core_ext'
10+
require 'yaml'
11+
12+
class YamlConfig
13+
def data
14+
@data ||= YAML.load(File.read(path)).deep_symbolize_keys
15+
end
16+
end
17+
18+
class EvergreenConfig < YamlConfig
19+
20+
def matrix_axes
21+
data[:axes].each_with_object({}) do |axis, node|
22+
node[axis[:id].underscore] = axis[:values].pluck(:id)
23+
end
24+
end
25+
26+
def axes
27+
@axes ||= data[:axes].each_with_object({}) do |axis, node|
28+
node[axis[:id].underscore.to_sym] = axis[:values].pluck(:id)
29+
end
30+
end
31+
32+
def variants
33+
@variants ||= data[:buildvariants].each_with_object([]) do |var, nodes|
34+
name = var[:matrix_name]
35+
36+
spec = var[:matrix_spec]
37+
tasks = var[:tasks]&.pluck(:name)
38+
raise("Invalid Evergreen buildvariant '#{name}'. Value for 'tasks' is empty.") unless tasks.present?
39+
raise("Unsupported Evergreen buildvariant '#{name}'. Cannot have more than one item in 'tasks'.") unless tasks.size == 1
40+
41+
node = {
42+
# matrix_name: name,
43+
# display_name: var[:display_name],
44+
mongodb: spec[:'mongodb-version'],
45+
ruby: spec[:jruby] || spec[:ruby],
46+
topology: spec[:topology],
47+
task: tasks.first,
48+
49+
# these will be later mapped to gemfile
50+
driver: spec[:driver],
51+
rails: spec[:rails],
52+
i18n: spec[:i18n],
53+
}
54+
55+
missing = node.map {|k, v| k if v.blank? }.compact
56+
missing -= %i[driver rails i18n]
57+
58+
if missing.present?
59+
puts "Skipping invalid Evergreen buildvariant '#{name}'. Keys missing: #{missing}"
60+
next
61+
end
62+
63+
nodes << node
64+
end
65+
end
66+
67+
protected
68+
69+
def path
70+
File.join(File.dirname(__FILE__), 'config.yml')
71+
end
72+
end
73+
74+
class GithubConfig < YamlConfig
75+
76+
def write(data)
77+
FileUtils.mkdir_p(File.dirname(path))
78+
data = data.deep_stringify_keys
79+
File.open(path, 'w+') {|f| f.write((comment || '') + data.to_yaml) }
80+
@data = data
81+
end
82+
83+
private
84+
85+
def path
86+
File.join(File.dirname(__FILE__), '../.github/workflows/test.yml')
87+
end
88+
89+
def comment
90+
<<~COMMENT
91+
# This file was auto-generated by .evergreen/make-github-actions
92+
# at #{Time.now.utc.rfc3339}
93+
COMMENT
94+
end
95+
end
96+
97+
class Transmogrifier
98+
SPLATTABLE_FIELDS = %i[mongodb topology ruby rails driver i18n]
99+
COMPACTABLE_FIELDS = %i[mongodb topology ruby gemfile]
100+
101+
attr_reader :eg_config,
102+
:gh_config
103+
104+
def initialize
105+
@eg_config = EvergreenConfig.new
106+
@gh_config = GithubConfig.new
107+
end
108+
109+
def transmogrify!
110+
gh_config.write(root_node)
111+
print_stats
112+
end
113+
114+
delegate :variants,
115+
:axes,
116+
to: :eg_config
117+
118+
def root_node
119+
{
120+
name: 'Run Mongoid Tests',
121+
on: %w[push pull_request],
122+
jobs: {
123+
build: {
124+
name: '${{matrix.ruby}} driver-${{matrix.driver}} mongodb-${{matrix.mongodb}} ${{matrix.topology}}',
125+
env: {
126+
CI: true,
127+
TESTOPTS: "-v"
128+
},
129+
'runs-on': 'ubuntu-latest',
130+
'continue-on-error': "${{matrix.experimental}}",
131+
strategy: {
132+
'fail-fast': false,
133+
matrix: { include: inclusions_node } },
134+
steps: steps_node
135+
}
136+
}
137+
}
138+
end
139+
140+
def print_stats
141+
puts "#{inclusions_node.size} unique matrix builds written"
142+
end
143+
144+
def inclusions_node
145+
@inclusions_node ||= begin
146+
inclusions = splat(variants).each {|node| transform_node!(node) }.reject {|node| unsupported?(node) }
147+
puts "#{inclusions.size} candidate matrix builds identified"
148+
compact_nodes(inclusions)
149+
end
150+
end
151+
152+
def compact_nodes(nodes)
153+
nodes.each_with_object({}) do |node, uniq_nodes|
154+
key = COMPACTABLE_FIELDS.map {|k| "#{k}:#{node[k]}" }.join('|')
155+
uniq_nodes[key] ||= node
156+
end.values
157+
end
158+
159+
def splat(array)
160+
# array
161+
SPLATTABLE_FIELDS.each do |field|
162+
array = array.each_with_object([]) do |node, new_array|
163+
case node[field]
164+
when Array
165+
node[field].each do |val|
166+
new_array << node.dup.tap {|n| n[field] = val }
167+
end
168+
when '*'
169+
axes[field].each do |val|
170+
new_array << node.dup.tap {|n| n[field] = val }
171+
end
172+
else
173+
new_array << node
174+
end
175+
end
176+
end
177+
array
178+
end
179+
180+
def unsupported?(node)
181+
node[:topology] == 'sharded_cluster'
182+
end
183+
184+
def transform_node!(node)
185+
node[:topology] = case node[:topology]
186+
when 'replica-set'
187+
'replica_set'
188+
when 'sharded-cluster'
189+
'sharded_cluster'
190+
else
191+
'server'
192+
end
193+
extract_gemfile!(node)
194+
set_experimental!(node)
195+
end
196+
197+
def set_experimental!(node)
198+
node[:experimental] = node[:gemfile].match?(/master|main|head/)
199+
end
200+
201+
def extract_gemfile!(node)
202+
node[:gemfile] = get_gemfile(*node.values_at(:driver, :rails, :i18n))
203+
end
204+
205+
# Ported from run-tests.sh
206+
def get_gemfile(driver, rails, i18n)
207+
driver, rails, i18n = [driver, rails, i18n].map {|v| v&.to_s }
208+
if driver && driver != 'current'
209+
"gemfiles/driver_#{driver.underscore}.gemfile"
210+
elsif rails && rails != '6.1' # TODO: "6.1" should be renamed to "current" in Evergreen
211+
"gemfiles/rails-#{rails}.gemfile"
212+
elsif i18n && i18n == '1.0'
213+
'gemfiles/i18n-1.0.gemfile'
214+
else
215+
'Gemfile'
216+
end
217+
end
218+
219+
def ruby_env
220+
{}
221+
end
222+
223+
def steps_node
224+
[ step_checkout,
225+
step_mongodb,
226+
step_ruby,
227+
step_bundle,
228+
step_test ]
229+
end
230+
231+
def step_checkout
232+
{
233+
name: "repo checkout",
234+
uses: "actions/checkout@v2",
235+
with: {
236+
submodules: "recursive"
237+
}
238+
}
239+
end
240+
241+
def step_mongodb
242+
{
243+
id: "start-mongodb"
244+
name: "start mongodb",
245+
uses: "mongodb-labs/drivers-evergreen-tools@master",
246+
with: {
247+
'version': '${{matrix.mongodb}}',
248+
'topology': '${{matrix.topology}}'
249+
}
250+
}
251+
end
252+
253+
def step_ruby
254+
{
255+
name: "load ruby",
256+
uses: "ruby/setup-ruby@v1",
257+
env: step_ruby_env,
258+
with: {
259+
'ruby-version': "${{matrix.ruby}}",
260+
bundler: 2
261+
}
262+
}
263+
end
264+
265+
def step_bundle
266+
{
267+
name: 'bundle',
268+
run: 'bundle install --jobs 4 --retry 3',
269+
env: step_ruby_env
270+
}
271+
end
272+
273+
def step_test
274+
{
275+
name: 'test',
276+
"timeout-minutes": 60,
277+
"continue-on-error": '${{matrix.experimental}}',
278+
run: 'bundle exec rake spec',
279+
env: step_ruby_env.merge({'MONGODB_URI': "${{ steps.start-mongodb.outputs.cluster-uri }}"})
280+
}
281+
end
282+
283+
def step_ruby_env
284+
{ 'BUNDLE_GEMFILE': '${{matrix.gemfile}}' }
285+
end
286+
end
287+
288+
Transmogrifier.new.transmogrify!

0 commit comments

Comments
 (0)