Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 182 lines (149 sloc) 5.066 kb
1 2 3 4 5 6 7 8 9 10 11 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
require 'date'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new do |t|
  t.rspec_opts = %w[--color]
  t.pattern = 'spec/**/*_spec.rb'
end

task :coverage => [:coverage_env, :spec]

task :coverage_env do
  ENV['COVERAGE'] = '1'
end

task :test => :spec
task :default => :spec

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'rdoc/task'
require 'engineyard/version'
Rake::RDocTask.new do |rdoc|
  rdoc.rdoc_dir = 'rdoc'
  rdoc.title = "engineyard #{EY::VERSION}"
  rdoc.rdoc_files.include('README*')
  rdoc.rdoc_files.include('lib/**/*.rb')
end

def remove_pre
  require 'engineyard/version'
  Gem::Version.create(EY::VERSION).release
end

def next_pre(version)
  digits = version.to_s.scan(/(\d+)/).map { |x| x.first.to_i }
  digits[-1] += 1
  digits.join('.') + ".pre"
end

def version_file
  Pathname.new('lib/engineyard/version.rb')
end

def write_version(new_version)
  with_version_contents do |contents|
    puts "engineyard (#{new_version})"

    if contents =~ /VERSION = '[^']+'/
      contents.sub(/VERSION = '[^']+'/,
                   "VERSION = '#{new_version}'")
    else
      raise "Problem writing version. Please check #{version_file}"
    end
  end
end

def write_serverside_version(serverside_version)
  with_version_contents do |contents|
    puts "engineyard-serverside (#{serverside_version})"

    words = "ENGINEYARD_SERVERSIDE_VERSION = ENV['ENGINEYARD_SERVERSIDE_VERSION'] ||"
    if contents =~ /#{Regexp.escape(words)} '[^']+'/
      contents.sub(/#{Regexp.escape(words)} '[^']+'/,
                   "#{words} '#{serverside_version}'")
    else
      raise "Problem writing serverside version. Please check #{version_file}"
    end
  end
end

def with_version_contents
  contents = version_file.read
  version_file.unlink
  version_file.open('w') do |f|
    f.write yield(contents)
  end
end

def release_changelog(version)
  clog = Pathname.new('ChangeLog.md')
  new_clog = clog.read.sub(/^## NEXT$/, <<-SUB.chomp)
## NEXT

*

## v#{version} (#{Date.today})
SUB
  clog.open('w') { |f| f.puts new_clog }
end

def update_serverside
  specs = Gem::SpecFetcher.fetcher.fetch(Gem::Dependency.new("engineyard-serverside"))
  latest_serverside_version = specs.map {|spec,| spec.version}.sort.last.to_s
  write_serverside_version(latest_serverside_version)
end

def update_serverside_adapter
  gem_name = "engineyard-serverside-adapter"
  specs = Gem::SpecFetcher.fetcher.fetch(Gem::Dependency.new(gem_name))
  latest_adapter_version = specs.map {|spec,| spec.version}.sort.last.to_s
  version_changed = false

  gemspec_file = Pathname.new('engineyard.gemspec')

  gemspec_file.open('r') do |read_gemfile|
    gemspec_file.unlink
    gemspec_file.open('w') do |write_gemfile|
      read_gemfile.each_line do |line|
        if line =~ /s.add_dependency\('#{gem_name}', '=([^']+)'/
          version_changed = ($1 != latest_adapter_version)
          puts "#{gem_name} (#{latest_adapter_version})"
          write_gemfile.write(" s.add_dependency(\'#{gem_name}\', \'=#{latest_adapter_version}\') # This line maintained by rake; edits may be stomped on\n")
        else
          write_gemfile.write(line)
        end
      end
    end
  end

  # re-bundle if the version changed
  if version_changed
    puts "Bundled gem version changed. Running bundle install..."
    Bundler.with_clean_env do
      system('bundle install')
    end
  end
end

namespace :update do
  desc "Update to latest version of engineyard-serverside"
  task "serverside" do
    update_serverside
  end

  desc "Update to latest version of engineyard-serverside-adapter"
  task "adapter" do
    update_serverside_adapter
  end
end

desc "Update to latest serverside and adapter versions"
task :update => ['update:serverside', 'update:adapter']

def run_commands(*cmds)
  cmds.flatten.each do |c|
    system(c) or raise "Command #{c.inspect} failed to execute; aborting!"
  end
end

desc "Release gem"
task :release do
  run_commands(
    "bundle install",
    "rake spec") # can't invoke directly; new gems won't get picked up

  new_version = remove_pre
  write_version new_version
  release_changelog(new_version)

  run_commands(
    "git add Gemfile ChangeLog.md lib/engineyard/version.rb engineyard.gemspec",
    "git commit -m 'Bump versions for release #{new_version}'",
    "gem build engineyard.gemspec")

  if system("gem spec engineyard-#{new_version}.gem | grep Syck")
    raise "Syck found in gemspec! Aborting!\nYou will need to revert the last commit yourself and build from a ruby without this Syck problem: 1.8 or a properly Psych linked 1.9."
  end

  write_version next_pre(new_version)

  run_commands(
    "git add lib/engineyard/version.rb",
    "git commit -m 'Add .pre for next release'",
    "git tag v#{new_version} HEAD^")

  puts <<-PUSHGEM
## To publish the gem: #########################################################

gem push engineyard-#{new_version}.gem
git push origin master v#{new_version}

## No public changes yet. ######################################################
PUSHGEM
end
Something went wrong with that request. Please try again.