Sha256: 3e706a4fe15d8147a06ba10d62f3280fb50b9765cadb9b95e6c10f356253a661

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

require 'pathname'
require 'yaml'

require_relative 'gemfile_selector'

module SchemaDev
  module Travis
    extend self

    TRAVIS_FILE = ".travis.yml"

    def build(config)
      env = []
      env << 'POSTGRESQL_DB_USER=postgres' if config.dbms.include? :postgresql
      env << 'MYSQL_DB_USER=travis' if config.dbms.include? :mysql
      env = env.join(' ')
      gemfiles = config.matrix.map{|entry| GemfileSelector.gemfile(entry.slice(:rails, :db)).to_s}.uniq
      exclude = config.matrix(excluded: :only).map { |entry| {}.tap {|ex|
        ex["rvm"] = entry[:ruby]
        ex["gemfile"] = GemfileSelector.gemfile(entry.slice(:rails, :db)).to_s
        ex["env"] = env if config.dbms.any?
      }}.reject{|ex| not gemfiles.include? ex["gemfile"]}

      {}.tap { |travis|
        travis["rvm"] = config.ruby.sort
        travis["gemfile"] = gemfiles.sort
        if config.dbms.any?
          travis["before_script"] = 'bundle exec rake create_databases'
          travis["after_script"] = 'bundle exec rake drop_databases'
          travis["env"] = env
        end
        travis["notifications"] = { "email" => config.notify } if config.notify.any?
        travis["matrix"] = { "exclude" => exclude.sort_by{|ex| [ex["rvm"], ex["gemfile"]]} } if exclude.any?
      }
    end

    def update(config)
      filepath = Pathname.new(TRAVIS_FILE)
      newtravis = build(config)
      oldtravis = YAML.load(filepath.read) rescue nil
      if oldtravis != newtravis
        header = <<-ENDYAML
# This file was auto-generated by the schema_dev tool, based on the data in
#                 ./schema_dev.yml
# Please do not edit this file; any changes will be overwritten next time
# schema_dev gets run.
ENDYAML
        filepath.write header + newtravis.to_yaml
        return true
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
schema_dev-1.1.0 lib/schema_dev/travis.rb
schema_dev-1.0.3 lib/schema_dev/travis.rb
schema_dev-1.0.2 lib/schema_dev/travis.rb
schema_dev-1.0.1 lib/schema_dev/travis.rb
schema_dev-1.0.0 lib/schema_dev/travis.rb