Sha256: 1b7e215da4e109d491dc13cf5aa0e8475fb75c8d46a9e8f277b0254b4aa8e62f

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

#!/bin/bash

set -e

notice () {
  echo "$@"
}

ruby_detect () {
  (
    test -f Gemfile && test -f Rakefile
  ) && (
    notice "found ruby project"
  )
}

rails_detect () {
  test -f Gemfile && cat Gemfile | grep gem | grep -q rails
}

rails_gen_database_spec_for_pg () {
  bundle show pg > /dev/null && (
    notice 'create config/database.yml for postgresql'
    cat > config/database.yml <<EOL
test:
  adapter: postgresql
  encoding: unicode
  database: rails_test
  username: postgres
  host: localhost
EOL
  )
}

rails_gen_database_spec_for_mysql () {
  bundle show mysql2 > /dev/null && (
    notice 'create config/database.yml for mysql'
    cat > config/database.yml <<EOL
test:
   adapter: mysql2
   encoding: utf8
   database: rails_test
   username: root
   host: localhost
EOL
  )
}

rails_db_create () {
  echo $ bundle exec rake db:create
  bundle exec rake db:create

  (
    test -f db/schema.rb && (
      echo $ bundle exec rake db:schema:load
      bundle exec rake db:schema:load
    )
  ) || (
    test -d db/migrate && (
      echo $ bundle exec rake db:migrate
      bundle exec rake db:migrate
    )
  )
}

rails_setup_database () {
  rails_detect && (
    (
      rails_gen_database_spec_for_pg ||
      rails_gen_database_spec_for_mysql
    ) &&
    rails_db_create
  )
}

ruby_setup_env () {
  echo $ export RAILS_ENV=test
  export RAILS_ENV=test

  echo $ export RACK_ENV=test
  export RACK_ENV=test

  echo $ export GEM_HOME=~/.rubygems
  export GEM_HOME=~/.rubygems

  test -f Gemfile && (
    echo $ 'export BUNDLE_GEMFILE=${PWD}/Gemfile'
    export BUNDLE_GEMFILE=${PWD}/Gemfile
  )
}

bundle_install () {
  test -f Gemfile && (
    notice '$ bundle install --retry=3 --jobs=4 --clean'
    bundle install --retry=3 --jobs=4 --clean
  )
}

run_rake_default () {
  echo $ bundle exec rake
  bundle exec rake
}

ruby_build () {
  notice 'build ruby project'

  ruby_setup_env &&
  bundle_install &&
  ( rails_setup_database || true ) &&
  run_rake_default
}

ruby_detect || exit 1
ruby_build || (
  exit $?
)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vx-builder-0.5.17 bin/vx_ruby_auto_build
vx-builder-0.5.16 bin/vx_ruby_auto_build