Sha256: 472d4ab56e6e6751c82497e5a7efbaee5fd24fb6476494f93f12d35351b8b784

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env ruby

require 'yaml'

def execute(*commands)
  commands.each do |command|
    system(command)
    next if $CHILD_STATUS.success?
    message = [
      'Executing shell command failed.',
      "  Command: #{command}",
      "  Status:  #{$CHILD_STATUS.exitstatus}"
    ].join("\n")
    raise message
  end
end

def reset_bundle
  execute(
    'rm -rf .bundle/gems',
    'rm -rf gemfiles/.bundle/gems',
    'rm -f *.lock',
    'rm -f gemfiles/*.lock'
  )
end

def with_rbenv(command)
  %{export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; #{command}}
end

def run(ruby_version, gemfile, task = 'test')
  ENV['RBENV_VERSION'] = ruby_version
  ENV['BUNDLE_GEMFILE'] = gemfile
  ENV['MOCHA_OPTIONS'] = 'debug'
  reset_bundle
  execute(
    with_rbenv("bundle install --gemfile=#{gemfile}"),
    with_rbenv("bundle exec rake #{task}")
  )
end

travis_config = YAML.safe_load(File.read('.travis.yml'))
build_configs = travis_config['matrix']['include']
travis_config['rvm'].each do |ruby_version|
  travis_config['gemfile'].each do |gemfile|
    travis_config['env'].each do |env|
      build_configs << { 'rvm' => ruby_version, 'gemfile' => gemfile, 'env' => env }
    end
  end
end

build_configs.each do |config|
  ruby_version = config['rvm']
  gemfile = config['gemfile']
  environment_variables = Hash[*config['env'].split.flat_map { |e| e.split('=') }]
  original_environment_variables = {}
  begin
    environment_variables.each do |k, v|
      original_environment_variables[k] = ENV[k]
      ENV[k] = v
    end
    p [ruby_version, gemfile, environment_variables]
    run(ruby_version, gemfile)
  ensure
    original_environment_variables.each do |k, v|
      ENV[k] = v
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mocha-1.7.0 bin/build-matrix