forked from mongodb/mongoid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into pr-5048
* upstream/master: (27 commits) Create security policy following github's template (mongodb#5070) MONGOID-5131 Use proper mdb <-> ubuntu versions (mongodb#5067) MONGOID-5131: Set up build pipeline for outside contributors (mongodb#5043) MONGOID-5165 Fix documentation link (mongodb#5065) Fix indentation MONGOID-5029 #empty method should use an #exists? rather than a #count query (mongodb#5029) MONGOID-5177 Fix flaky contextual spec (mongodb#5064) MONGOID-5170 - Fix more typos mostly in code docs and code comments (mongodb#5056) MONGOID-5105 Allow block form in Mongoid::Association::EmbedsMany::Proxy#count (mongodb#5060) MONGOID-5162 Add a release note for the planned changes in ObjectId#as_json (mongodb#5059) MONGOID-5171 - Make the minimum Ruby version 2.5 (mongodb#5058) MONGOID-5130 Remove conn count from client spec (mongodb#5055) Add driver 2.15 to compat table Fix MONGOID-5136 .touch with custom field is broken for embedded documents (mongodb#5039) MONGOID-5144 Add a deprecation warning when using the legacy query cache (mongodb#5042) MONGOID-???? Replace field[0] == ?$ with field.start_with?('$') -- easier to read and 30%+ faster (mongodb#5052) MONGOID-???? - Remove BSON::ObjectId#as_json as we will defer to the bson-ruby gem implementation. (mongodb#5057) MONGOID-4737 Deprecate the :compact option on Document#as_json (mongodb#5040) MONGOID-5143 [Code Comments Only] Remove magic comment "# encoding: utf-8" (mongodb#5041) Remove all @SInCE comments. These are generally not useful as: (mongodb#5037) ...
- Loading branch information
Showing
874 changed files
with
2,264 additions
and
4,565 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,288 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# TODO: Support topology=sharded-cluster (requires better MongoDB Github Action) | ||
# TODO: Support i18n-fallbacks test | ||
# TODO: Support app-tests tests | ||
|
||
require 'fileutils' | ||
require 'active_support/dependencies/autoload' | ||
require 'active_support/core_ext' | ||
require 'yaml' | ||
|
||
class YamlConfig | ||
def data | ||
@data ||= YAML.load(File.read(path)).deep_symbolize_keys | ||
end | ||
end | ||
|
||
class EvergreenConfig < YamlConfig | ||
|
||
def matrix_axes | ||
data[:axes].each_with_object({}) do |axis, node| | ||
node[axis[:id].underscore] = axis[:values].pluck(:id) | ||
end | ||
end | ||
|
||
def axes | ||
@axes ||= data[:axes].each_with_object({}) do |axis, node| | ||
node[axis[:id].underscore.to_sym] = axis[:values].pluck(:id) | ||
end | ||
end | ||
|
||
def variants | ||
@variants ||= data[:buildvariants].each_with_object([]) do |var, nodes| | ||
name = var[:matrix_name] | ||
|
||
spec = var[:matrix_spec] | ||
tasks = var[:tasks]&.pluck(:name) | ||
raise("Invalid Evergreen buildvariant '#{name}'. Value for 'tasks' is empty.") unless tasks.present? | ||
raise("Unsupported Evergreen buildvariant '#{name}'. Cannot have more than one item in 'tasks'.") unless tasks.size == 1 | ||
|
||
node = { | ||
# matrix_name: name, | ||
# display_name: var[:display_name], | ||
mongodb: spec[:'mongodb-version'], | ||
ruby: spec[:jruby] || spec[:ruby], | ||
topology: spec[:topology], | ||
task: tasks.first, | ||
|
||
# these will be later mapped to gemfile | ||
driver: spec[:driver], | ||
rails: spec[:rails], | ||
i18n: spec[:i18n], | ||
} | ||
|
||
missing = node.map {|k, v| k if v.blank? }.compact | ||
missing -= %i[driver rails i18n] | ||
|
||
if missing.present? | ||
puts "Skipping invalid Evergreen buildvariant '#{name}'. Keys missing: #{missing}" | ||
next | ||
end | ||
|
||
nodes << node | ||
end | ||
end | ||
|
||
protected | ||
|
||
def path | ||
File.join(File.dirname(__FILE__), 'config.yml') | ||
end | ||
end | ||
|
||
class GithubConfig < YamlConfig | ||
|
||
def write(data) | ||
FileUtils.mkdir_p(File.dirname(path)) | ||
data = data.deep_stringify_keys | ||
File.open(path, 'w+') {|f| f.write((comment || '') + data.to_yaml) } | ||
@data = data | ||
end | ||
|
||
private | ||
|
||
def path | ||
File.join(File.dirname(__FILE__), '../.github/workflows/test.yml') | ||
end | ||
|
||
def comment | ||
<<~COMMENT | ||
# This file was auto-generated by .evergreen/make-github-actions | ||
# at #{Time.now.utc.rfc3339} | ||
COMMENT | ||
end | ||
end | ||
|
||
class Transmogrifier | ||
SPLATTABLE_FIELDS = %i[mongodb topology ruby rails driver i18n] | ||
COMPACTABLE_FIELDS = %i[mongodb topology ruby gemfile] | ||
|
||
attr_reader :eg_config, | ||
:gh_config | ||
|
||
def initialize | ||
@eg_config = EvergreenConfig.new | ||
@gh_config = GithubConfig.new | ||
end | ||
|
||
def transmogrify! | ||
gh_config.write(root_node) | ||
print_stats | ||
end | ||
|
||
delegate :variants, | ||
:axes, | ||
to: :eg_config | ||
|
||
def root_node | ||
{ | ||
name: 'Run Mongoid Tests', | ||
on: %w[push pull_request], | ||
jobs: { | ||
build: { | ||
name: '${{matrix.ruby}} driver-${{matrix.driver}} mongodb-${{matrix.mongodb}} ${{matrix.topology}}', | ||
env: { | ||
CI: true, | ||
TESTOPTS: "-v" | ||
}, | ||
'runs-on': 'ubuntu-latest', | ||
'continue-on-error': "${{matrix.experimental}}", | ||
strategy: { | ||
'fail-fast': false, | ||
matrix: { include: inclusions_node } }, | ||
steps: steps_node | ||
} | ||
} | ||
} | ||
end | ||
|
||
def print_stats | ||
puts "#{inclusions_node.size} unique matrix builds written" | ||
end | ||
|
||
def inclusions_node | ||
@inclusions_node ||= begin | ||
inclusions = splat(variants).each {|node| transform_node!(node) }.reject {|node| unsupported?(node) } | ||
puts "#{inclusions.size} candidate matrix builds identified" | ||
compact_nodes(inclusions) | ||
end | ||
end | ||
|
||
def compact_nodes(nodes) | ||
nodes.each_with_object({}) do |node, uniq_nodes| | ||
key = COMPACTABLE_FIELDS.map {|k| "#{k}:#{node[k]}" }.join('|') | ||
uniq_nodes[key] ||= node | ||
end.values | ||
end | ||
|
||
def splat(array) | ||
# array | ||
SPLATTABLE_FIELDS.each do |field| | ||
array = array.each_with_object([]) do |node, new_array| | ||
case node[field] | ||
when Array | ||
node[field].each do |val| | ||
new_array << node.dup.tap {|n| n[field] = val } | ||
end | ||
when '*' | ||
axes[field].each do |val| | ||
new_array << node.dup.tap {|n| n[field] = val } | ||
end | ||
else | ||
new_array << node | ||
end | ||
end | ||
end | ||
array | ||
end | ||
|
||
def unsupported?(node) | ||
node[:topology] == 'sharded_cluster' | ||
end | ||
|
||
def transform_node!(node) | ||
node[:topology] = case node[:topology] | ||
when 'replica-set' | ||
'replica_set' | ||
when 'sharded-cluster' | ||
'sharded_cluster' | ||
else | ||
'server' | ||
end | ||
extract_gemfile!(node) | ||
set_experimental!(node) | ||
end | ||
|
||
def set_experimental!(node) | ||
node[:experimental] = node[:gemfile].match?(/master|main|head/) | ||
end | ||
|
||
def extract_gemfile!(node) | ||
node[:gemfile] = get_gemfile(*node.values_at(:driver, :rails, :i18n)) | ||
end | ||
|
||
# Ported from run-tests.sh | ||
def get_gemfile(driver, rails, i18n) | ||
driver, rails, i18n = [driver, rails, i18n].map {|v| v&.to_s } | ||
if driver && driver != 'current' | ||
"gemfiles/driver_#{driver.underscore}.gemfile" | ||
elsif rails && rails != '6.1' # TODO: "6.1" should be renamed to "current" in Evergreen | ||
"gemfiles/rails-#{rails}.gemfile" | ||
elsif i18n && i18n == '1.0' | ||
'gemfiles/i18n-1.0.gemfile' | ||
else | ||
'Gemfile' | ||
end | ||
end | ||
|
||
def ruby_env | ||
{} | ||
end | ||
|
||
def steps_node | ||
[ step_checkout, | ||
step_mongodb, | ||
step_ruby, | ||
step_bundle, | ||
step_test ] | ||
end | ||
|
||
def step_checkout | ||
{ | ||
name: "repo checkout", | ||
uses: "actions/checkout@v2", | ||
with: { | ||
submodules: "recursive" | ||
} | ||
} | ||
end | ||
|
||
def step_mongodb | ||
{ | ||
id: "start-mongodb" | ||
name: "start mongodb", | ||
uses: "mongodb-labs/drivers-evergreen-tools@master", | ||
with: { | ||
'version': '${{matrix.mongodb}}', | ||
'topology': '${{matrix.topology}}' | ||
} | ||
} | ||
end | ||
|
||
def step_ruby | ||
{ | ||
name: "load ruby", | ||
uses: "ruby/setup-ruby@v1", | ||
env: step_ruby_env, | ||
with: { | ||
'ruby-version': "${{matrix.ruby}}", | ||
bundler: 2 | ||
} | ||
} | ||
end | ||
|
||
def step_bundle | ||
{ | ||
name: 'bundle', | ||
run: 'bundle install --jobs 4 --retry 3', | ||
env: step_ruby_env | ||
} | ||
end | ||
|
||
def step_test | ||
{ | ||
name: 'test', | ||
"timeout-minutes": 60, | ||
"continue-on-error": '${{matrix.experimental}}', | ||
run: 'bundle exec rake spec', | ||
env: step_ruby_env.merge({'MONGODB_URI': "${{ steps.start-mongodb.outputs.cluster-uri }}"}) | ||
} | ||
end | ||
|
||
def step_ruby_env | ||
{ 'BUNDLE_GEMFILE': '${{matrix.gemfile}}' } | ||
end | ||
end | ||
|
||
Transmogrifier.new.transmogrify! |
Oops, something went wrong.