Module: SchemaDev::Travis

Extended by:
Travis
Included in:
Travis
Defined in:
lib/schema_dev/travis.rb

Constant Summary collapse

TRAVIS_FILE =
".travis.yml"

Instance Method Summary collapse

Instance Method Details

#build(config) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/schema_dev/travis.rb', line 12

def build(config)
  env = []
  addons = {}
  if config.dbms.include?(:postgresql)
    env << 'POSTGRESQL_DB_USER=postgres'
    addons['postgresql'] = "9.4"
  end
  if config.dbms.include?(:mysql)
    env << 'MYSQL_DB_USER=travis'
  end
  env = env.join(' ')

  gemfiles = config.matrix.map{|entry| GemfileSelector.gemfile(entry.slice(:activerecord, :db)).to_s}.uniq

  exclude = config.matrix(excluded: :only).map { |entry| {}.tap {|ex|
    ex["rvm"] = entry[:ruby]
    ex["gemfile"] = GemfileSelector.gemfile(entry.slice(:activerecord, :db)).to_s
    ex["env"] = env unless env.empty?
  }}.reject{|ex| not gemfiles.include? ex["gemfile"]}

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

#update(config) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/schema_dev/travis.rb', line 48

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