mongodb/mongo-ruby-driver

View on GitHub
.evergreen/update-evergreen-configs

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

require 'erubi'
require 'erubi/capture_end'
require 'tilt'
autoload :YAML, 'yaml'

class Runner
  def run
    transform('config.yml')

    @atlas = true
    transform('config-atlas.yml')
  end

  def transform(output_file_name)
    contents = <<-EOT
# GENERATED FILE - DO NOT EDIT.
# Run ./.evergreen/update-evergreen-configs to regenerate this file.

EOT

    template_path = File.join(File.dirname(__FILE__), 'config/common.yml.erb')
    #contents << ERB.new(File.read(template_path)).result(get_binding)
    contents << Tilt.new(template_path, engine_class: Erubi::CaptureEndEngine).render(self)

    template_path = File.join(File.dirname(__FILE__), 'config/axes.yml.erb')
    contents << Tilt.new(template_path, engine_class: Erubi::CaptureEndEngine).render(self)

    if @atlas
      template_path = File.join(File.dirname(__FILE__), 'config/atlas.yml.erb')
      contents << Tilt.new(template_path, engine_class: Erubi::CaptureEndEngine).render(self)
    else
      template_path = File.join(File.dirname(__FILE__), 'config/standard.yml.erb')
      contents << Tilt.new(template_path, engine_class: Erubi::CaptureEndEngine).render(self)
    end

    output_path = File.join(File.dirname(__FILE__), output_file_name)
    File.open(output_path, 'w') do |f|
      f << contents
    end
  end

  def get_binding
    binding
  end

  DEBIAN_FOR_RUBY = {
    'ruby-2.3' => 'debian92',
    'ruby-2.4' => 'debian92',
    'ruby-2.5' => 'debian10',
    'ruby-2.6' => 'debian10',
    'ruby-2.7' => 'debian10',
    'ruby-3.0' => 'debian10',
  }

  def standard_debian_rubies(rubies, key: nil, &block)
    rubies.flatten!
    text = block.call
    contents = YAML.load(text)
    out = rubies.map do |ruby|
      contents.merge(
        'matrix_name' => "#{contents['matrix_name']} - #{ruby}",
        'matrix_spec' => contents['matrix_spec'].merge(
          'ruby' => ruby,
          key || 'os' => DEBIAN_FOR_RUBY.fetch(ruby),
        ),
      )
    end.to_yaml
    text =~ /\A\n?(\s+)/
    unless text
      raise "Couldn't figure out indentation level"
    end
    indent = ' ' * ($1.length - 2)
    "\n" + out.sub(/\A---.*\n/, indent).gsub("\n", "\n#{indent}")
  end
end

Runner.new.run