programandoarg/pg_rails

View on GitHub
bin/bumpto

Summary

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

require 'fileutils'
require 'dotenv'

Dotenv.load('.env.local', '.env')

def system!(cmd)
  abort("Error en: #{cmd}") unless system(cmd)
end

newversion = ARGV[0] || raise('usage: bumpto version')

MAIN_BRANCH = 'master'
current_branch = `git branch --show-current`

if current_branch != "#{MAIN_BRANCH}\n" && !ENV['DONT_REBASE']
  system!('git fetch --all --prune')
  system("git branch -d #{MAIN_BRANCH}")
  system!("git checkout -b #{MAIN_BRANCH}")
  system!("git branch -d #{current_branch}")
  system!("git rebase origin/#{MAIN_BRANCH}")
end

pkgjson = File.read('package.json')
newcontent = pkgjson.sub /"version": .*,/, "\"version\": \"#{newversion}\","
File.write('package.json', newcontent)

engver = File.read('pg_rails/lib/version.rb')
newcontent = engver.sub /VERSION = .*/, "VERSION = '#{newversion}'"
File.write('pg_rails/lib/version.rb', newcontent)

system! 'bundle'

system! 'git add .'
system! "git commit -m 'Version #{newversion}'"

system! 'bundle exec rake release_all'

proj = ENV['UPGRADE_PROJECT_AFTER_PGRAILS']
if proj
  SECONDS = 30
  puts "Dandole tiempo a rubygems para que actualice para actualizar #{proj}"
  SECONDS.times.each do |i|
    left = SECONDS - i
    puts "Dandole tiempo a rubygems para que actualice: #{left}"
    sleep 1
  end

  FileUtils.chdir("../#{proj}") do
    system! './bin/update_pgrails'
  end
end